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

**URL:** <https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 15, 2020, 11:22am UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634 "2020-04-15T11:22:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [April 15, 2020, 11:22am UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/1 "2020-04-15T11:22:18Z")

</div>

According to [Filesystem · The Julia Language](https://docs.julialang.org/en/v1/base/file/#Filesystem-1)  
I’d like to

```julia
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
julia> cd(D:\\..\\..\\home\\amend")
ERROR: syntax: "\" is not a unary operator
julia> cd("~")
ERROR: IOError: chdir ~: no such file or directory (ENOENT)

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 15, 2020, 12:04pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/2 "2020-04-15T12:04:20Z")

</div>

> [@1634](#):
>
> `julia> cd("D:\\Julia")`

~~Use `raw"D:\\Julia"`, as otherwise `\\` is interpreted as an [escape](https://en.wikipedia.org/wiki/Escape_character) for a single backslash.~~ Oh, silly me, you _want_ a single backslash here. I can never keep Windows path conventions straight.

> [@1634](#):
>
> `cd(D:\\..\\..\\home\\Amend")`

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

[![xkcd 1638](https://global.discourse-cdn.com/julialang/original/3X/a/5/a53167e2b3f78b38c75aebb874be1a74a2eff0b3.png)](https://xkcd.com/1638/)

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [April 15, 2020, 12:18pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/3 "2020-04-15T12:18:14Z")

</div>

LOL This is why I always use `joinpath` instead of backslashes. 🤣

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [April 15, 2020, 2:26pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/4 "2020-04-15T14:26:48Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [April 15, 2020, 2:40pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/5 "2020-04-15T14:40:08Z")

</div>

Happy to know more option:)

```julia
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**."

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [April 15, 2020, 2:42pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/6 "2020-04-15T14:42:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 15, 2020, 2:43pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/7 "2020-04-15T14:43:45Z")

</div>

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

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`

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [April 15, 2020, 4:30pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/8 "2020-04-15T16:30:24Z")

</div>

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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/5/c57106eb6630bc8d9280719b5b7bdf7c8d6fdcc7.png)

> [@stevengj](#):
>
> Since `D:\` is a root path, why would `D:\..` exist?

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.

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [April 15, 2020, 4:37pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/9 "2020-04-15T16:37:34Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [April 15, 2020, 4:52pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/10 "2020-04-15T16:52:33Z")

</div>

Thanks but

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

help?> iswindows
search:

Couldn't find iswindows

```

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [April 15, 2020, 5:06pm UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/11 "2020-04-15T17:06:05Z")

</div>

Sorry I didn’t remember `Sys.iswindows`. See here [Handling Operating System Variation · The Julia Language](https://docs.julialang.org/en/v1/manual/handling-operating-system-variation/)

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [April 17, 2020, 5:12am UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/12 "2020-04-17T05:12:03Z")

</div>

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

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

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

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 17, 2020, 5:27am UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/13 "2020-04-17T05:27:35Z")

</div>

This is discussed in `?joinpath`.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [April 17, 2020, 6:19am UTC](https://discourse.julialang.org/t/cd-directory-out-of-c-or-d/37634/14 "2020-04-17T06:19:55Z")

</div>

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.
