The absolute path of the project root directory in Julia

Access to the root directory of the project file located in PROJECT_ROOT/lib/code.jlcan be obtained using this code:

root = dirname(dirname(@__FILE__))

Using dirname()twice seems pretty ugly. Is there a better way to do this? With Ruby, I would use this code:

root = File.expand_path('../', File.dirname(__FILE__))
+4
source share
1 answer

Thanks for learning about:

"/"*relpath((@__FILE__)*"/../..","/")

According to it ?relpath, it gives the path from the location of the second argument in the file system to the first argument. Is this better than a double solution dirname?

A variant of the same amenities:

normpath(joinpath(@__FILE__,"..",".."))

The closest Ruby equivalent could be:

realpath(dirname(@__FILE__)*"/..")
+3
source

Source: https://habr.com/ru/post/1629251/


All Articles