Add takeAllParents
This commit is contained in:
parent
7d0ca1c230
commit
b7cd5ba857
@ -59,6 +59,7 @@ module System.Posix.FilePath (
|
|||||||
, splitPath
|
, splitPath
|
||||||
, joinPath
|
, joinPath
|
||||||
, splitDirectories
|
, splitDirectories
|
||||||
|
, takeAllParents
|
||||||
|
|
||||||
-- * Trailing slash functions
|
-- * Trailing slash functions
|
||||||
, hasTrailingPathSeparator
|
, hasTrailingPathSeparator
|
||||||
@ -500,6 +501,21 @@ splitDirectories x
|
|||||||
splitter = filter (not . BS.null) . BS.split pathSeparator
|
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
|
-- Trailing slash functions
|
||||||
|
Loading…
Reference in New Issue
Block a user