Helix
Helix

Reputation: 191

Can't open file in Julia

This might be an incredibly basic question but I can't find the answer online. I can't open any files in Julia when they aren't in the same directory as my script. So if I want to do readall(open("~/Documents/dictionary.txt")) I always get a file does not exist error. This is an application where the script takes file paths (which may be absolute or relative) from the command line. Python handles this pretty easily but Julia seems to be having trouble for me. Thanks for the help.

Upvotes: 2

Views: 1372

Answers (1)

Abhijith
Abhijith

Reputation: 1218

On unix based systems the function expanduser("~") returns the current user's home directory, so appending this at the beginning this will work,

julia> open(expanduser("~")*"/Documents/dictionary.txt")

Credits to @Dan Getz.

Upvotes: 3

Related Questions