# Split path to its parts

**URL:** <https://discourse.julialang.org/t/split-path-to-its-parts/15427>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 24, 2018, 2:46pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427 "2018-09-24T14:46:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 24, 2018, 2:46pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/1 "2018-09-24T14:46:10Z")

</div>

I want to split a path into all its directory names. On Linux I would achieve this with `split` and a the path separator of `/`:

```julia
julia> split("/home/me/some/thing", '/')
5-element Array{SubString{String},1}:
 ""     
 "home" 
 "me"   
 "some" 
 "thing"

```

But it would be nice if this worked everywhere. Or if these was a better way…

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [September 24, 2018, 2:53pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/2 "2018-09-24T14:53:21Z")

</div>

I went looking for this functionality recently too. And [we’re not alone](https://github.com/JuliaLang/julia/issues/24477)

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [September 24, 2018, 3:13pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/3 "2018-09-24T15:13:23Z")

</div>

See also [https://github.com/JuliaLang/julia/pull/28156](https://github.com/JuliaLang/julia/pull/28156)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 24, 2018, 3:13pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/4 "2018-09-24T15:13:48Z")

</div>

While this is fixed in `Base`, a (trivial) package could be very useful. I guess the only thing it needs to do is encode platform-dependent behavior.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 24, 2018, 4:05pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/5 "2018-09-24T16:05:44Z")

</div>

I had forgotten about that PR but I think we should merge it.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 24, 2018, 6:21pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/6 "2018-09-24T18:21:22Z")

</div>

Oh wow, awesome.

> [@Tamas\_Papp](#):
>
> a (trivial) package could be very useful.

So once/if that PR is merged, what would a package help with?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 24, 2018, 6:42pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/7 "2018-09-24T18:42:52Z")

</div>

I was assuming the PR was dormant. If it is merged, that’s of course preferable.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 24, 2018, 6:57pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/8 "2018-09-24T18:57:19Z")

</div>

Merged so in Julia 1.1 you’ll be able to call `splitpath`. This change could potentially be added to `Compat` to allow use `splitpath` on older Julia versions.

---

<div class="post-metadata">

**Author:** ![VinodV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinodv/32/32733_2.png) [@VinodV](https://discourse.julialang.org/u/VinodV)\
**Post date:** [August 14, 2024, 3:59am UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/9 "2024-08-14T03:59:05Z")

</div>

```julia
?path 
help?> path
search: pathof mkpath ispath relpath abspath realpath normpath joinpath

Couldn't find path
Perhaps you meant pathof, ispath, mkpath, put!, cat, coth, hash, match or tanh
  No documentation found.

  Binding path does not exist.

```

not showing `splitpath`

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [August 14, 2024, 5:10pm UTC](https://discourse.julialang.org/t/split-path-to-its-parts/15427/10 "2024-08-14T17:10:27Z")

</div>

`splitpath` certainly still exists (the output below is for Julia 1.10.4):

```julia-repl
julia> splitpath
splitpath (generic function with 2 methods)

help?> splitpath
search: splitpath

  splitpath(path::AbstractString) -> Vector{String}

  Split a file path into all its path components. This is the opposite of joinpath. Returns an array of substrings,
  one for each directory or file in the path, including the root directory if present.

  │ Julia 1.1
  │
  │ This function requires at least Julia 1.1.

  Examples
  ≡≡≡≡≡≡≡≡

  julia> splitpath("/home/myuser/example.jl")
  4-element Vector{String}:
   "/"
   "home"
   "myuser"
   "example.jl"

```

The list you get from `help?> path` simply is not exhaustive.
