Browse Source

Add takeAllParents

travis
Julian Ospald 4 years ago
parent
commit
b7cd5ba857
No known key found for this signature in database GPG Key ID: 511B62C09D50CD28
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      hpath-filepath/src/System/Posix/FilePath.hs

+ 16
- 0
hpath-filepath/src/System/Posix/FilePath.hs View File

@@ -59,6 +59,7 @@ module System.Posix.FilePath (
, splitPath
, joinPath
, splitDirectories
, takeAllParents

-- * Trailing slash functions
, hasTrailingPathSeparator
@@ -500,6 +501,21 @@ splitDirectories x
splitter = filter (not . BS.null) . BS.split pathSeparator


-- |Get all parents of a path.
--
-- >>> takeAllParents "/abs/def/dod"
-- ["/abs/def","/abs","/"]
-- >>> takeAllParents "/foo"
-- ["/"]
-- >>> takeAllParents "/"
-- []
takeAllParents :: RawFilePath -> [RawFilePath]
takeAllParents p
| np == BS.singleton pathSeparator = []
| otherwise = takeDirectory np : takeAllParents (takeDirectory np)
where
np = normalise p


------------------------
-- Trailing slash functions


Loading…
Cancel
Save