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)
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.
The directory where the current script is located is provided by the @__DIR__
macro.
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