Behavior of the pwd() statement, Windows 10


#1

Hello,

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()
"/home/JuliaUser"

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

julia> pwd()
"C:\\Users\\guent\\AppData\\Local\\Julia-1.0.3"

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:


#2

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?


#3

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?


#4

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


#5

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


#6

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


#7

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.


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

julia> cur_dir = pwd()
"C:\\Temp"

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

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

julia>

#9

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

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

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