Behavior of the pwd() statement, Windows 10


The pwd statement has been discussed here before and I may not understand the answer. The following behavior can be found in the documentation:

julia> pwd()

When I execute the statement (Windows 10) I get the following output:

julia> pwd()

In addition to the difference to the documentation this of course leads to an “ArgumentError” in the further using. Is this desired or is this a Julia malfunction? :confused:

pwd returns the current working directory, see the docs which obviously will not be the same everywhere.

What do you mean by this? What are you using the result for?

1 Like

Thanks for your quick answer. For Julia, it’s of course a difference whether in a string a “/” or a “” character is contained. Under Windows 10 I even get the:"\"

If I now read the directory via pwd(), save it in a variable and then load a file later (by using of this variable), I get the error message mentioned above (or that this string does not describe a “file”). The reason is the “\” sign. If I replace it manually with “/” everything works. But it can’t be a solution, can it?

Sorry! My system lost “” and “\”…

What’s happend? “”"" and “”\""…?

Sorry, take a look to my first post! You will see the character which I would like to “show”… :thinking:

It would help to include a code snippet that is failing. It’s hard to know exactly what problem you’re having otherwise.

You shouldn’t need to manually replace the \\ with / for things to work. Generally you should be using joinpath to create paths that work on your system, e.g. joinpath(pwd(), "somefile.txt") will create the proper absolute path for "somefile.txt" within your current directory.

julia> cd("C:\\Temp")

julia> cur_dir = pwd()

julia> open(joinpath(cur_dir,"tst.txt"),"w") do fil
           write(fil, "Hello World!")

julia> open("tst.txt") do fil
Hello World!


Many thanks for the joinpath statement! :smiley: It works:

cur_dir = pwd()
dateiname ="Text.txt"
datei = open(joinpath(cur_dir, dateiname))
inhalt = readlines(datei)

["Das ist der 1. Text!", "Das ist der 2. Text!", "Das ist der 3. Text!"]