Join parts of a URL - joinpath?



I’d like to build a url like “” from a Vector

parts = ["", "get", "data"]

At first sight, on a *nix system I will do

julia> joinpath(parts...)

but I think joinpath is system dependant ie on Windows it may use \ instead of /

Is there a function which always use “/” (even with Windows system)

With Python, we have os.path.join and urllib.parse.urljoin
But I haven’t found a join... function in

Kind regards


I’m aware of

join(parts, "/")

but I wonder if a more “high level” function exists


Does have anything useful to you?


I don’t see in URIParser.jl a function to concatenate parts of an url.


Seems to me that this code from the README might be helpful, but this might not be everything you need:

Additionally, there is a method for taking the parts of the URI individually, as well as a convenience method taking host and path which constructs a valid HTTP URL:

julia> URI("hdfs","hdfshost",9000,"/root/folder/file.csv","","","user:password")

julia> URI("","/some/path")


oh yes… I was looking at a function in utils.jl
Thank you


Glad I could help. My apologies - I did not notice that you had already checked the package. I could’ve saved you an iteration.


But that’s not perfect…
How to do this if "/root/folder/file.csv" is in a Vector like ["root", "folder", "file.csv"]


The URI takes a standard path, so joinpath should do what you need in *nix: that is, you can pass in the output of joinpath:

a = ["/","foo", "bar", "baz"]
URI("", joinpath(a...))

This might not work on Windows, though, given that joinpath will likely use backslashes there.

There might be a more elegant way of doing this as well.


How about a long-hand?

reduce(*, ["root", "folder", "file.csv"] .* "/")[1:end - 1] ==

joinpath("", "foo", "bar", "baz")

works fine even on Windows, it returns