Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia - Platform specific file paths

Tags:

path

julia

Whats the most clever (or preferably the right way) to handle different file system paths?

i.e

Windows

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

Unix

cd("Folder/file.jl")

The only solution that comes to mind is declairing a global variable at runtime

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

but that looks awfully dodgy

like image 981
isebarn Avatar asked Sep 19 '16 09:09

isebarn


1 Answers

joinpath("Folder","file.jl") should do the trick.

From the REPL ?joinpath gives:

joinpath(parts...) -> AbstractString

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

So, if needed more than two path parts can be joined as in:

joinpath("dir1","dir2","file1") == "dir1/dir2/file1" (on a Linux machine)

like image 188
Dan Getz Avatar answered Oct 19 '22 01:10

Dan Getz