Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute path of the project root directory in Julia

Tags:

julia

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__))
like image 781
Powers Avatar asked Sep 26 '22 08:09

Powers


1 Answers

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__)*"/..")
like image 90
Dan Getz Avatar answered Sep 29 '22 05:09

Dan Getz