处理不同文件系统路径的最聪明(或最好是正确的方法)是什么?
IE
视窗
cd("Folder\\\\file.jl") #this becomes "\\"
Run Code Online (Sandbox Code Playgroud)
Unix
cd("Folder/file.jl")
Run Code Online (Sandbox Code Playgroud)
想到的唯一解决方案是在运行时声明一个全局变量
@windows_only global slash = "\\"
@linux_only global slash = "/"
Run Code Online (Sandbox Code Playgroud)
但这看起来非常狡猾
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.
Run Code Online (Sandbox Code Playgroud)
因此,如果需要,可以连接两个以上的路径部分,如下所示:
joinpath("dir1","dir2","file1") == "dir1/dir2/file1" (在 Linux 机器上)
| 归档时间: |
|
| 查看次数: |
854 次 |
| 最近记录: |