2016-09-19 94 views
3

处理不同文件系统路径最聪明(或最好是正确的方式)是什么?Julia - 平台特定文件路径

的Windows

cd("Folder\\\\file.jl") #this becomes "\\" 

的Unix

cd("Folder/file.jl") 

想到的唯一的办法就是declairing在运行时的全局变量

@windows_only global slash = "\\" 
@linux_only global slash = "/" 

但这看起来很狡猾

+1

'joinpath(”文件夹“,”文件“)'是你的朋友。 –

+0

谢谢!那是我需要的 – isebarn

回答

3

joinpath("Folder","file.jl")应该做的伎俩。

从REPL ?joinpath给出:

joinpath(parts...) -> AbstractString 

Join path components into a full path. If some argument is an absolute 
path, then prior components are dropped. 

因此,如果需要多于两个的路径部分可以被连接为:

joinpath("dir1","dir2","file1") == "dir1/dir2/file1"(Linux机器上)