Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to reset the current working directory in Julia?

Suppose the current working directory is C:\ (the directory where the .jl file is saved), and then I switch the cwd to some subfolders to perform some tasks. Is there anyway of directly resetting the cwd back to C:\ after that, i.e. the initial cwd? Or alternatively, is there anyway of locating the directory where the .jl file being run is located, independent of the current working directory? (Without saving the cwd as a variable beforehand)

like image 965
Sato Avatar asked Dec 18 '22 14:12

Sato


2 Answers

You can use the do keyword together with the cd function:

cd("/some/path") do
   pwd() # or do some other work here
end

This will change the working directory to /some/path, allow you to do some work, and automatically return to the original working directory after the end keyword.

like image 195
David Varela Avatar answered Jun 14 '23 04:06

David Varela


The directory where the current script is located is provided by the @__DIR__ macro.

like image 29
giordano Avatar answered Jun 14 '23 02:06

giordano