23

In R, starting from any working directory, I can do

setwd("~/Desktop")

and this is consistent with how my linux distribution interprets cd at the command line. But Julia does not seem to recognize the ~/ notation:

julia> cd("~/Desktop")
ERROR: chdir ~/Desktop: No such file or directory
 in systemerror at error.jl:38
 in cd at file.jl:13

Is this a bug?

1

2 Answers 2

43

The idiom is just different as you can see from the source. If you invoke cd() without arguments, it defaults to the home directory. The function homedir() can be used to prepend the home directory.

julia> homedir()
"/Users/jeffw"

julia> cd("/")

julia> pwd()
"/"

julia> cd()

julia> pwd()
"/Users/jeffw"

Combining things

julia> cd("$(homedir())/Desktop")

julia> pwd()
"/Users/jeffw/Desktop"
2
  • And if you want to change to a folder that is in the home directory? Like the OP is asking about?
    – Dason
    Jul 19, 2014 at 15:04
  • 7
    cd("$(homedir())/Desktop) isn't portable, should be cd(joinpath(homedir()),"Desktop")) Jul 30, 2014 at 22:15
3

The problem is that Julia doesn't expand the ~. You need to manually provide the full path. This is being worked on, but I'm on my phone right now and can't find issue.

1
  • see @Dason's comment on the original post.
    – Ben Bolker
    Jul 19, 2014 at 15:38

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.