Joinpath() in wsl2 mounted drives

I would like to read/write files in a folder in D drives say D:\data. I hope it works for Julia both in windows and wsl2. I tried joinpath() but cannot figure out how to make it.

I start Julia in the home dir (or some project dir in various drives). I have explored @DIR and homedir(). Can joinpath() or some other function achieve the requests below?

  1. Under Ubuntu in wsl2, the home dir is “/home/workstation” and the file is in the mounted drive “/mnt/d/data”. How can I read.CSV(joinpath(…))?

  2. Under Windows, the home dir is “C:\Users\workstation” and the file is in another drive: “D:\data”. How can I read.CSV(joinpath(…))?

  3. Is there a uniform way to read files in the data folder of D drive no matter I start Julia from the home dir of Windows or Ubuntu?

I know I can do these by typing all the real paths, but I belive there should be some smart way.

You can check the operating system like this and use that to just set a base path.

drivepath = Sys.iswindows() ? "D:" : "/mnt/d"
datapath = joinpath(drivepath, "data", ...)

If you can’t do a relative path and the absolute path is os specifik I think this might be the easiest/cleanest way.

1 Like

Yeps, thanks, this should work. It seems to be a little hard for a relative path of different or mounted drives.