Cd() directory out of C:\\ or D:\\

According to Filesystem · The Julia Language
I’d like to

julia> cd("/home/amend")
ERROR: IOError: chdir /home/amend: no such file or directory (ENOENT)

while
julia> cd("D:\\Julia") #working
**Is it a must to start from C:\\ or D:\\ (in Window10)? What if I want to cd directory out of them?

In linux filesystem:
/home/amend #this branch
/mnt/d/ #rather than starting from D:\\ here

The tricks as below fails as well.

julia> cd(D:\\..\\..\\home\\amend")
ERROR: syntax: "\" is not a unary operator
julia> cd("~")
ERROR: IOError: chdir ~: no such file or directory (ENOENT)

Use raw"D:\\Julia", as otherwise \\ is interpreted as an escape for a single backslash. Oh, silly me, you want a single backslash here. I can never keep Windows path conventions straight.

You were missing the opening quote. Use cd(raw"D:\..\..\home\Amend")

xkcd 1638

5 Likes

LOL This is why I always use joinpath instead of backslashes. :rofl:

1 Like

Xp. But this seems not to work TAT
julia> cd(raw"D:\…“)
julia> cd(raw"D:\…\…”)
julia> pwd()
“D:\”

julia> cd(raw"D:\…\…\home")
ERROR: IOError: chdir D:\…\…\home: no such file or directory (ENOENT)

julia> cd(raw"D:\…\…\home\amend")
ERROR: IOError: chdir D:\…\…\home\amend: no such file or directory (ENOENT)

Happy to know more option:)

julia> joinpath("home/amend/ngsJulia/ngsPool", "functions.jl")
"home/amend/ngsJulia/ngsPool/functions.jl"

julia> pwd()
"D:\\Julia"

but it seems not to set home directory or open a file. I guess I didn’t get

  1. what joinpath() should be used for (except termininologies like nodes)
  2. whether it cannot allow path out of mnt as well, if looking at its documentary:

" Join path components into a full path. If some argument is an absolute path or (on Windows) has a drive specification that doesn’t match the drive computed for the join of the preceding paths, then prior components are dropped."

joinpath just correctly creates the path string. You should pass it to cd

2 Likes

Do you mean .. and not ...?

Since D:\ is a root path, why would D:\.. exist?

joinpath creates a path out of components, e.g. joinpath("D:", "home") makes D:\home

The double \ doesn’t show rightly in the post.

Thanks I get it~
but is there any chance to set /home/amend instead of /mnt/d/anyfile as home directory in julia? This would be helpful to work between linux and julia.

if Sys.iswindows()
    cd(raw"D:\home")
else
    cd("/home/amend")
end

Thanks but

julia> cd("/home/amend")
ERROR: IOError: chdir /home/amend: no such file or directory (ENOENT)

help?> iswindows
search:

Couldn't find iswindows

Sorry I didn’t remember Sys.iswindows. See here Handling Operating System Variation · The Julia Language

1 Like

How does joinpath work when you want to construct the full path? Here is returns C:Users and not C:\\Users.

julia> joinpath("C:", "Users")
"C:Users"

julia> joinpath("C", "Users")
"C\\Users"

1 Like

This is discussed in ?joinpath.

1 Like

Thank you.

And the missing backslash joinpath("C:\A","c:b") in the help page for joinpath has already been fixed in the new docs.

2 Likes