# How to execute a bit of Julia code/function from a specific directory

**URL:** <https://discourse.julialang.org/t/how-to-execute-a-bit-of-julia-code-function-from-a-specific-directory/127916>\
**Category:** General Usage\
**Tags:** filesystem\
**Created:** [April 10, 2025, 10:18am UTC](https://discourse.julialang.org/t/how-to-execute-a-bit-of-julia-code-function-from-a-specific-directory/127916 "2025-04-10T10:18:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [April 10, 2025, 10:18am UTC](https://discourse.julialang.org/t/how-to-execute-a-bit-of-julia-code-function-from-a-specific-directory/127916/1 "2025-04-10T10:18:26Z")

</div>

I have a folder (“MyFolder”) that looks something like:  
MyFolder:

- data.ext
- read\_data.jl

next, “read\_data.jl” looks ike this:

```julia
using DataImporter
data = DataImporter.import("data.ext")

```

Somewhere else I then run

```julia
data = include("path/to/MyFolder/read_data.jl")

```

The problem is that when I do this, the line `data = DataImporter.import("data.ext")` is executed from the folder where I initially run the code (and so the path to `"data.ext"` is wrong).

Is there a way to, in

```julia
using DataImporter
data = DataImporter.import("data.ext")

```

add something to ensure that the line `data = DataImporter.import("data.ext")` (but idealy nothing else) is executed with the file path in relation to the location of the “read\_data.jl” script?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 10, 2025, 1:02pm UTC](https://discourse.julialang.org/t/how-to-execute-a-bit-of-julia-code-function-from-a-specific-directory/127916/2 "2025-04-10T13:02:05Z")

</div>

Use [`@ __DIR__ `](https://docs.julialang.org/en/v1/base/base/#Base.@ __DIR__ ):

```julia
data = DataImporter.import(joinpath(@ __DIR__ , "data.ext"))

```

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [April 11, 2025, 9:07am UTC](https://discourse.julialang.org/t/how-to-execute-a-bit-of-julia-code-function-from-a-specific-directory/127916/3 "2025-04-11T09:07:44Z")

</div>

> [@fredrikekre](#):
>
> `joinpath(@ __DIR__ , "data.ext")`

Thanks a lot 🙂
