Joinpath fails on splitdrive output

I would have expected joinpath(splitdrive(pwd())) == pwd(). On Julia 1.8.5

julia> pwd()

julia> joinpath(splitdrive(pwd()))

julia> joinpath(splitpath(pwd())) == pwd()

I am not sure if this is fixed by Revise Windows implementation of splitdrive by GunnarFarneback · Pull Request #42204 · JuliaLang/julia · GitHub

Not sure what the reasoning for above behaviour is, if there is any, but there is also splitpath available which behaves as you expect it.

1 Like

There is some text in the docstring of joinpath which I do not fully understand but seems to be related:

help?> joinpath
search: joinpath

  joinpath(parts::AbstractString...) -> String
  joinpath(parts::Vector{AbstractString}) -> String
  joinpath(parts::Tuple{AbstractString}) -> String

  Join path components into a full path. If some argument is an absolute path or (on Windows) has a drive
  specification that doesn't match the drive computed for the join of the preceding paths, then prior components are

  Note on Windows since there is a current directory for each drive, joinpath("c:", "foo") represents a path relative
  to the current directory on drive "c:" so this is equal to "c:foo", not "c:\foo". Furthermore, joinpath treats this
  as a non-absolute path and ignores the drive letter casing, hence joinpath("C:\A","c:b") = "C:\A\b".


  julia> joinpath("/home/myuser", "example.jl")

  julia> joinpath(["/home/myuser", "example.jl"])

Thanks for your help. It is related to my previous question Splitpath on UNC shares where joinpath(splitdrive) also fails:

julia> splitdrive("\\\\svfae01-solid01\\SED\\SE")
("\\\\svfae01-solid01\\SED", "\\SE")

julia> joinpath(splitdrive("\\\\svfae01-solid01\\SED\\SE"))

If someone wants to drive that PR forward, feel free to take over. I do want to see that fixed but I don’t use Windows myself, so it’s always low on my priority list and I can’t easily test anything.

1 Like