无论如何,有没有要重置Julia中的当前工作目录? [英] Is there anyway to reset the current working directory in Julia?
问题描述
假设当前工作目录为C:\
(保存.jl文件的目录),然后将cwd切换到某些子文件夹以执行某些任务.
无论如何,之后是否可以直接将cwd重置为C:\
,即初始cwd?或者,是否可以独立于当前工作目录定位正在运行的.jl文件所在的目录? (无需将cwd预先保存为变量)
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)
推荐答案
您可以使用 cd
函数:
You can use the do
keyword together with the cd
function:
cd("/some/path") do
pwd() # or do some other work here
end
这会将工作目录更改为/some/path
,允许您执行一些工作,并在使用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.
这篇关于无论如何,有没有要重置Julia中的当前工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!