2016-09-19 91 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機器上)