# Adding non-source files to a package

**URL:** <https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017>\
**Category:** General Usage\
**Tags:** package\
**Created:** [November 29, 2022, 11:01pm UTC](https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017 "2022-11-29T23:01:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hros](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hros](https://discourse.julialang.org/u/hros)\
**Post date:** [November 29, 2022, 11:01pm UTC](https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017/1 "2022-11-29T23:01:17Z")

</div>

Is it possible to access non-source files in a package git?  
specifically, I would like a text file used for testing the package to be available to users of the package.  
When I just placed the text file in the root directory of the package, I saw that it ended up in `.julia/packages/<package_name>/<generic_name>/<file.txt>`  
Where should I place the file, and how can I access it from Julia?

---

<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:** [November 30, 2022, 6:58am UTC](https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017/2 "2022-11-30T06:58:12Z")

</div>

How are the users supposed to interact with it?

Anyway, you can place it wherever you want in your git repository and a function in the package can find its own directory with the macro `@ __DIR__ ` and then use `joinpath` to construct a path to your text file.

---

<div class="post-metadata">

**Author:** ![hros](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hros](https://discourse.julialang.org/u/hros)\
**Post date:** [November 30, 2022, 8:33am UTC](https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017/3 "2022-11-30T08:33:29Z")

</div>

thanks  
Is there an option to access the file without adding code to the package?  
consider a typical package structure:

```julia
package
  |-- Manifest.toml
  |-- Project.toml 
  |-- README.md
  |-- src
     |-- main.jl
  |-- file.txt

```

is it possible to access `file.txt` from the REPL after importing the package?

---

<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:** [November 30, 2022, 8:40am UTC](https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017/4 "2022-11-30T08:40:21Z")

</div>

Yes, `pathof` can help you there.

```julia
julia> using Example

julia> print(read(joinpath(dirname(pathof(Example)), "../README.md"), String))
Example Julia package repo.
[...]

```

---

<div class="post-metadata">

**Author:** ![hros](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hros](https://discourse.julialang.org/u/hros)\
**Post date:** [November 30, 2022, 12:22pm UTC](https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017/5 "2022-11-30T12:22:04Z")

</div>

thanks @GunnarFarneback , the `pathof` function is what I was looking for.  
In my case the syntax is:

```julia
julia> lines = readlines(joinpath(dirname(pathof(package_name)), "../file.txt"));

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [November 30, 2022, 9:52pm UTC](https://discourse.julialang.org/t/adding-non-source-files-to-a-package/91017/6 "2022-11-30T21:52:57Z")

</div>

Consider also placing it under a `test` folder…
