File path "/" vs "\" (fslash vs backslash)

When I copy a file-path from the windows file explorer, the format is like this: C:\Users\MyUser\Folder\File.jl

When I want to read this file in Julia, when trying to read a CSV or include() custom functions, I try to use this command:
include(“C:\Users\MyUser\Folder\File.jl”)

The problem is that this string contains backslashes, and so it is not parsed correctly. But this is how things have to be to maintain the "\UnicodeSymbol " functionality, right? My current workaround is to manually change every \ into /, but it just feels like a better option has to exist.

So the question is generally how can I copy file-paths in a way that Julia can correctly parse on a windows computer, which I believe boils down to if/how I can change the direction of the slashes when copying a path from the file explorer. Any fixes out there?

The usual trick is to do raw"C:\Users\MyUser\Folder\File.jl".

5 Likes

Nice, that works :smiley: For anyone googling this issue, here is a link to the documentation:
https://docs.julialang.org/en/v1/manual/strings/#man-raw-string-literals-1

2 Likes