# Pwd() cd() and I/O text for open files from pc

**URL:** https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204
**Category:** New to Julia
**Created:** [June 19, 2021, 10:23pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204 "2021-06-19T22:23:33Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 19, 2021, 10:23pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/1 "2021-06-19T22:23:33Z")

</div>

Where I’m wrong?

(I’m following on YT Julia for nervous beginners) but now I’ returning in my steps because I met same problem in I/O text files where julia answer me: “no such file or directory” after order fh = open(“fname”)

 ![Immagine](https://global.discourse-cdn.com/julialang/original/3X/c/a/ca48b64fc1f02c9d2bc2e48713ae1eff2d9831fa.png)

after writing pwd() Julia write the same directory

---

<div class="post-metadata">

### Author: ![Erasmo98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erasmo98/32/26098_2.png) [@Erasmo98](https://discourse.julialang.org/u/Erasmo98)
#### Post date: [June 19, 2021, 11:53pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/2 "2021-06-19T23:53:50Z")

</div>

`cd` stands for “change directory”, but you’re passing as argument a path to a file (.jl), not to a directory (cartella).

Restart Julia and try the following:

```julia
julia> pwd()
"C:\\Users\\Amministratore"

julia> cd(".\\Julia")

julia> pwd()
"C:\\Users\\Amministratore\\Julia"

julia> io = open("myfile.jl", "w");

julia> write(io, "Hello world!");

julia> close(io);

julia> io = open("myfile.jl", "r");

julia> read(io, String)
"Hello world!"

```

You can also open the file in a text editor and see for yourself that “Hello world!” was written.

Finally, check out this topic: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757).

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 12:01pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/3 "2021-06-20T12:01:57Z")

</div>

Hey, thank you for your time that are you helping me, but seems that’s not working.

 ![2021-06-20 13_58_11-Greenshot](https://global.discourse-cdn.com/julialang/original/3X/3/2/323a9184fcd94509bd1e12e37add9912247bf21a.png)

i read from others forums that should be a Julia bug, but the first time that i did work well.

I don’t know what to do.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [June 20, 2021, 12:03pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/4 "2021-06-20T12:03:22Z")

</div>

you don’t `cd` into a FILE, you only `cd` into a directory (folder). `myfile.jl` is a file, you can’t `cd` into it

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 20, 2021, 12:23pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/5 "2021-06-20T12:23:35Z")

</div>

As @jling mentioned you can’t `cd` into a file. To get the parent folder from a file path you can do the following:

```julia
filepath = raw"C:\Users\Amministratore\Julia\myfile.jl"
parent_dir = dirname(filepath)
cd(parent_dir)

```

You can also check if the path is valid by using `isfile`,`ispath` or `isdir`

```julia
ispath(raw"C:\Users\Amministratore\Julia\myfile.jl")
isfile(raw"C:\Users\Amministratore\Julia\myfile.jl")
isdir(raw"C:\Users\Amministratore\Julia\myfile.jl")

```

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 4:45pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/6 "2021-06-20T16:45:21Z")

</div>

thanks, give me “false” 🤷‍♂️  
ispath–\> false  
isfile–\>false  
isdir–\>false LOL

even  
`include("myfile.jl")` give me no such file or directory

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [June 20, 2021, 4:48pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/7 "2021-06-20T16:48:33Z")

</div>

`Users` not `User`

you can use `<tab>` complete the path as you’re typing it

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 20, 2021, 5:02pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/8 "2021-06-20T17:02:31Z")

</div>

What do you get when executing this?

```julia
c = raw"C:\Users\Amministratore\Julia\myfile.jl"
ispath.(accumulate(joinpath,splitpath(c)))

```

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 5:05pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/9 "2021-06-20T17:05:37Z")

</div>

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

manipulated? (julia libraries?)

because the first time was ok…

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 20, 2021, 5:08pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/10 "2021-06-20T17:08:23Z")

</div>

Ok, so you don’t have a file called myfile.jl in C:\Users\Amministratore\Julia

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 5:08pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/11 "2021-06-20T17:08:43Z")

</div>

yeah but the screenshot confirm it LOL

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 20, 2021, 5:10pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/12 "2021-06-20T17:10:49Z")

</div>

so this should give you all the files in the Julia folder

```julia
c = raw"C:\Users\Amministratore\Julia\myfile.jl"
cd(dirname(c))
readdir()

```

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 5:15pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/13 "2021-06-20T17:15:07Z")

</div>

exactly give me correct all them

`3-element Vector {String}: myfile.jl.txt new1.jl newfile.jl.jl`

already done all things with others 2 .jl

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 20, 2021, 5:16pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/14 "2021-06-20T17:16:54Z")

</div>

So you created a new file in windows while the file explorer was hiding the filename extensions.  
The file is called `myfile.jl.txt` instead of` myfile.jl`

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 5:18pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/15 "2021-06-20T17:18:21Z")

</div>

already done with others 2 same things that you suggested, doesn’t change nothing

`ispath(raw"C:\Users\Amministratore\Julia\newfile.jl") false`

isfile and others… i tried all

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 20, 2021, 5:27pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/16 "2021-06-20T17:27:22Z")

</div>

To read the content of the file you can run this

```julia
c = raw"C:\Users\Amministratore\Julia\myfile.jl.txt"
data = open(c,"r") do io
  read(io,String)
end
@show data

```

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 5:29pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/17 "2021-06-20T17:29:08Z")

</div>

from data give me error, goodbye.

I leave (even with others files in the folder instead of myfile, like newfile, new1 (in jl) )

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [June 20, 2021, 5:29pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/18 "2021-06-20T17:29:54Z")

</div>

ok, so you need to: [https://www.howtogeek.com/205086/beginner-how-to-make-windows-show-file-extensions/](https://www.howtogeek.com/205086/beginner-how-to-make-windows-show-file-extensions/)

again, this is why I asked you to use `tab` to complete the path, so you know what exactly IS in there.

---

<div class="post-metadata">

### Author: ![12345\_12345](https://avatars.discourse-cdn.com/v4/letter/1/977dab/32.png) [@12345\_12345](https://discourse.julialang.org/u/12345_12345)
#### Post date: [June 20, 2021, 6:38pm UTC](https://discourse.julialang.org/t/pwd-cd-and-i-o-text-for-open-files-from-pc/63204/19 "2021-06-20T18:38:59Z")

</div>

don’t exagerate! i got the same problem with another individual between C: and D: directory so I created another folder in external drive and resolved in this mode. Ok. I can go on 😂

It’s resolved after also uninstalled/re-installed annnddd " it’s very important.

Thank’s to all. I love YOU ALL for the patience, I know tutor was a better choice…
