Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splitpath to match joinpath #24477

Closed
oxinabox opened this issue Nov 5, 2017 · 2 comments
Closed

splitpath to match joinpath #24477

oxinabox opened this issue Nov 5, 2017 · 2 comments
Labels
filesystem Underlying file system and functions that use it strings "Strings!"

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Nov 5, 2017

Roughly speaking
joinpath(args...)=join(args, '/')
plus some magic to let it properly handle cases like joinpath("a/", "b")=="a/b"
(I know it actually isn't implemented much like that)

Analogously we should have its inverse
Roughly:
splitpath(arg)=split(arg, '/', keep=false)

so splitpath("a/b/c.txt")==["a", "b", "c.txt"].

I have added to my project:

julia> function splitpath(path::AbstractString)
       ret=String[]
       while(true)
       path, lastpart = splitdir(path)
       length(lastpart)>0 && unshift!(ret, lastpart)
       length(path)==0 && break
       end
       return ret
       end
splitpath (generic function with 1 method)

julia> splitpath("a/b/c")
3-element Array{String,1}:
 "a"
 "b"
 "c"

julia> splitpath("a/b/c/")
3-element Array{String,1}:
 "a"
 "b"
 "c"

julia> splitpath("a/b//c/")
3-element Array{String,1}:
 "a"
 "b"
 "c"

Though I am not sure of the best way to do this

@ararslan ararslan added filesystem Underlying file system and functions that use it strings "Strings!" labels Nov 5, 2017
@StefanKarpinski
Copy link
Member

I agree that we should have this – I wanted it myself recently. Not sure if keep is necessary.

@rfourquet
Copy link
Member

Closed by #28156.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filesystem Underlying file system and functions that use it strings "Strings!"
Projects
None yet
Development

No branches or pull requests

4 participants