From d373cacedb1895c3099269fb668a3a05eab73739 Mon Sep 17 00:00:00 2001 From: Chris Done Date: Mon, 11 May 2015 18:59:26 +0200 Subject: [PATCH] Add dirname --- src/Path.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Path.hs b/src/Path.hs index 18d18c7..d150148 100644 --- a/src/Path.hs +++ b/src/Path.hs @@ -29,6 +29,7 @@ module Path ,isParentOf ,parent ,filename + ,dirname -- * Conversion ,toFilePath ) @@ -251,7 +252,18 @@ parent (Path fp) = -- @filename (parent \<\/> filename a) == a@ -- filename :: Path b File -> Path Rel File -filename (Path l) = Path (normalizeFile (FilePath.takeFileName l)) +filename (Path l) = + Path (normalizeFile (FilePath.takeFileName l)) + +-- | Extract the last directory name of a path. +-- +-- The following properties hold: +-- +-- @dirname (parent \<\/> dirname a) == a@ +-- +dirname :: Path b Dir -> Path Rel Dir +dirname (Path l) = + Path (last (FilePath.splitPath l)) -------------------------------------------------------------------------------- -- Internal functions