This post is tested under masOS High Sierra and Julia v1.6.1.
Suppose you have folder named A
with following directory tree:
├── B
│ ├── D
│ │ ├── F
│ │ └── YourScript.jl
│ └── E
└── C
Current directory #
pwd() # returns "/Users/USERNAME/Desktop/A/B/D"
Or,
@__DIR__ # returns /Users/USERNAME/Desktop/A/B/D"
To go up by one level #
You need to use dirname()
dirname(pwd()) # returns "/Users/USERNAME/Desktop/A/B"
Or,
cd(pwd, "..") # returns "/Users/USERNAME/Desktop/A/B"
To go up by one level and access another folder #
In this case, to access E
.
You can use the function of joinpath()
joinpath(dirname(pwd()), "E") # returns "/Users/USERNAME/Desktop/A/B/E"
Or, use string()
:
string(dirname(pwd()), "/E") # returns "/Users/USERNAME/Desktop/A/B/E"
To go up by more than one level #
cd(pwd, "../..") # returns "/Users/USERNAME/Desktop/A"
Home directory #
Use homedir()
homedir() ## returns "/Users/USERNAME"
References #
-
How to get the parent directory of the current working directory in Julia on Stack Overflow
-
waTeim’s response to the question of Setting working directory: Julia versus R on Stack Overflow.
Last modified on 2021-10-05