# When developing a package, how do you access files in the package directory structure?

**URL:** <https://discourse.julialang.org/t/when-developing-a-package-how-do-you-access-files-in-the-package-directory-structure/57750>\
**Category:** General Usage\
**Tags:** package\
**Created:** [March 22, 2021, 9:16pm UTC](https://discourse.julialang.org/t/when-developing-a-package-how-do-you-access-files-in-the-package-directory-structure/57750 "2021-03-22T21:16:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![3ArnjN](https://avatars.discourse-cdn.com/v4/letter/3/ba8739/32.png) [@3ArnjN](https://discourse.julialang.org/u/3ArnjN)\
**Post date:** [March 22, 2021, 9:16pm UTC](https://discourse.julialang.org/t/when-developing-a-package-how-do-you-access-files-in-the-package-directory-structure/57750/1 "2021-03-22T21:16:21Z")

</div>

I am working on a [package](https://github.com/BoZenKhaa/ReverseGeocode.jl) that’s supposed to download and use files in the `data` directory inside the package directory structure.

Originally, I was using `./data` as a path of the data directory. That worked fine for me as a developer, but when I tried to install the package as a user, the package stopped working as `./data` was relative to the user’s project, not the install directory of my package.

So my first question is: what’s the correct way to get path relative to the installed package root directory? And a second question is how can I test that the package works correctly for end users before releasing a new version?

I saw a [post](https://discourse.julialang.org/t/path-of-this-package/16401/4) recommending `pathof(@ __MODULE__ )`, but I am not sure that is the correct way since it seems to return an incorrect path `/Absolute/path/to/project/MyPackage/src/MyPackage.jl` when I am developing the package.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 22, 2021, 10:09pm UTC](https://discourse.julialang.org/t/when-developing-a-package-how-do-you-access-files-in-the-package-directory-structure/57750/2 "2021-03-22T22:09:27Z")

</div>

Use a file-relative path. You can use `joindir(@ __DIR__ , "..", "data", "somefile")` from a file in your `package/src` directory to access a file `somefile` in your `package/data` directory.

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [March 22, 2021, 11:18pm UTC](https://discourse.julialang.org/t/when-developing-a-package-how-do-you-access-files-in-the-package-directory-structure/57750/3 "2021-03-22T23:18:44Z")

</div>

You also can use `pathof(MyModule)` where `MyModule` is the module of the your package (you need to import it first). It will returns the path to the `Project.toml`. You can use `dirname(dirname(pathof(MyModule)))` to get the root folder path.

---

<div class="post-metadata">

**Author:** ![3ArnjN](https://avatars.discourse-cdn.com/v4/letter/3/ba8739/32.png) [@3ArnjN](https://discourse.julialang.org/u/3ArnjN)\
**Post date:** [March 23, 2021, 12:18am UTC](https://discourse.julialang.org/t/when-developing-a-package-how-do-you-access-files-in-the-package-directory-structure/57750/4 "2021-03-23T00:18:53Z")

</div>

Oh, I now realize that it actually returns path to the file that defines the module. Thanks a lot for quick responses, I ended up going with `pathof(MyModule)`.
