# Working with path at module level?

**URL:** https://discourse.julialang.org/t/working-with-path-at-module-level/110142
**Category:** General Usage
**Tags:** question
**Created:** [February 13, 2024, 10:26am UTC](https://discourse.julialang.org/t/working-with-path-at-module-level/110142 "2024-02-13T10:26:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [February 13, 2024, 10:26am UTC](https://discourse.julialang.org/t/working-with-path-at-module-level/110142/1 "2024-02-13T10:26:29Z")

</div>

Hello,

I have a package with directories structured like this:

- Packgage
  - data
    - datafile.txt

  - src
    - package.jl

In package.jl, there is a function

```julia
function foo()
    f = read("data/datafile.txt")
    #do smth
end

```

This works fine when I am working in the Julia environment “Package”, but I would like someone to be able to `add Package`, `using Package`, `Package.foo()`.  
But in that case, they obtain a `SystemError: opening file "data/datafile.txt": No such file`  
This is because they are in another environment than that of the package. Is there a way to tell Julia to use paths that are within the package?

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [February 13, 2024, 10:32am UTC](https://discourse.julialang.org/t/working-with-path-at-module-level/110142/2 "2024-02-13T10:32:00Z")

</div>

You could use one of `@ __FILE__ ` or `@ __DIR__ ` to get the location of the current file.

```julia
function foo()
    f = read(joinpath(@ __DIR__ , "..", "data/datafile.txt"))
    #do smth
end

```

If you need to find the root folder frequently and from different paths within, then you could define a helper function at a fixed location to return the module root path.

---

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [February 13, 2024, 10:34am UTC](https://discourse.julialang.org/t/working-with-path-at-module-level/110142/3 "2024-02-13T10:34:35Z")

</div>

Amazing, this will do the trick. Thank you.
