# Relocatability of @\_\_DIR\_\_

**URL:** https://discourse.julialang.org/t/relocatability-of-dir/96700
**Category:** General Usage
**Tags:** question, macros, package-compiler
**Created:** [March 28, 2023, 9:07am UTC](https://discourse.julialang.org/t/relocatability-of-dir/96700 "2023-03-28T09:07:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sstroemer](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sstroemer](https://discourse.julialang.org/u/sstroemer)
#### Post date: [March 28, 2023, 9:07am UTC](https://discourse.julialang.org/t/relocatability-of-dir/96700/1 "2023-03-28T09:07:17Z")

</div>

I am using the `DIR` macro in a function like:

```julia
function foo()
    return joinpath(@ __DIR__ , "myfile.ext")
end

```

If function `foo()` gets precompiled using `PackageCompiler.jl` into a sysimage, the `@ __DIR__ ` is “hardcoded” into the function. This entails that I can not relocate that sysimage anywhere (which otherwise works as expected).

Is there any other way to lookup that folder, so that it gets evaluated at runtime?

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [March 28, 2023, 10:17am UTC](https://discourse.julialang.org/t/relocatability-of-dir/96700/2 "2023-03-28T10:17:51Z")

</div>

Does this work?

```julia
my_dir = Ref{String}()

function __init__ ()
    my_dir[] = @ __DIR__
end

function foo()
    return joinpath(my_dir[], "myfile.ext")
end

```

---

<div class="post-metadata">

### Author: ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)
#### Post date: [March 28, 2023, 1:49pm UTC](https://discourse.julialang.org/t/relocatability-of-dir/96700/3 "2023-03-28T13:49:46Z")

</div>

> **[GitHub - JuliaPackaging/RelocatableFolders.jl](https://github.com/JuliaPackaging/RelocatableFolders.jl)**
>
> Contribute to JuliaPackaging/RelocatableFolders.jl development by creating an account on GitHub.

But see the caveats in the README.
