How to get the path to module dir?

In the module I need to open a file located in the same directory, so I do

fd = open("foo.txt")

But when I use the module from another directory, it complains that “foo.txt” does not exist. So, how can I specify a path to the module definition directory?

1 Like

joinpath(dirname(pathof(MyModule)), "foo.txt")