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

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

using these two inside this .jl file

@__FILE__
@__DIR__

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

This is perfect! Thank you so much!