# How to specify paths relative to a file rather than current directory?

**URL:** <https://discourse.julialang.org/t/how-to-specify-paths-relative-to-a-file-rather-than-current-directory/89092>\
**Category:** General Usage\
**Tags:** path\
**Created:** [October 21, 2022, 11:48pm UTC](https://discourse.julialang.org/t/how-to-specify-paths-relative-to-a-file-rather-than-current-directory/89092 "2022-10-21T23:48:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lkmc](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lkmc](https://discourse.julialang.org/u/lkmc)\
**Post date:** [October 21, 2022, 11:48pm UTC](https://discourse.julialang.org/t/how-to-specify-paths-relative-to-a-file-rather-than-current-directory/89092/1 "2022-10-21T23:48:48Z")

</div>

I have a file that I would like to be able to be read from multiple directories. I cannot use absolute paths because I need the code to be able to run for different users on different machines who may have put their repos in different places. If I have the following directory structure:

top\_dir → sub\_dir → sub\_sub\_dir

I have function1 in sub\_dir that calls function2 in sub\_sub\_dir that reads a file in top\_dir. Function2 is written so that the relative path to the file is “…/…/file”. If I do this:

sub\_sub\_dir \> julia function2()

it works fine, but if I do either of the following

sub\_dir \> julia sub\_sub\_dir/function2()  
sub\_dir \> julia function1()

then it can’t find the file unless I change the relative path to be “…/file”. It would be awesome if I could specify the path relative to the directory of the function that reads the file, but it appears that the relative path is relative to the current working directory. Does anyone have any suggestions for ways around this? TIA

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 22, 2022, 12:00am UTC](https://discourse.julialang.org/t/how-to-specify-paths-relative-to-a-file-rather-than-current-directory/89092/2 "2022-10-22T00:00:05Z")

</div>

> [@lkmc](#):
>
> to the directory of the function that reads the file

using these two inside this `.jl` file

```julia
@ __FILE__
@ __DIR__

```

should be helpful, since you can find the relative path starting from a given file in your project folder

---

<div class="post-metadata">

**Author:** ![lkmc](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@lkmc](https://discourse.julialang.org/u/lkmc)\
**Post date:** [October 22, 2022, 12:25am UTC](https://discourse.julialang.org/t/how-to-specify-paths-relative-to-a-file-rather-than-current-directory/89092/3 "2022-10-22T00:25:00Z")

</div>

This is perfect! Thank you so much!
