8

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

2
  • 2
    joinpath("folder","file") is your friend.
    – Dan Getz
    Sep 19, 2016 at 9:27
  • thanks! thats what I need
    – isebarn
    Sep 19, 2016 at 9:41

1 Answer 1

14

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.