The project root directory of a file located in PROJECT_ROOT/lib/code.jl
can be accessed with 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__))
Thanks for making me find out about:
"/"*relpath((@__FILE__)*"/../..","/")
According to ?relpath
, it gives a path from the location of the second argument in the file-system, to the first argument. Is this better than the double dirname
solution?
A variant of the same niceness is:
normpath(joinpath(@__FILE__,"..",".."))
Closest to Ruby equivalent might be:
realpath(dirname(@__FILE__)*"/..")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With