now dirname and basename work well on Windows and other platform that can use backslash on path
This commit is contained in:
parent
5be5242113
commit
d07bb01b48
@ -243,16 +243,36 @@ a <> b = a ++ b
|
|||||||
-- if null, return "."
|
-- if null, return "."
|
||||||
--
|
--
|
||||||
dirname :: FilePath -> FilePath
|
dirname :: FilePath -> FilePath
|
||||||
dirname p =
|
dirname p =
|
||||||
case reverse $ dropWhile (/= '/') $ reverse p of
|
let x = findIndices (== '\\') p
|
||||||
[] -> "."
|
y = findIndices (== '/') p
|
||||||
p' -> p'
|
in
|
||||||
|
if not $ null x
|
||||||
|
then if not $ null y
|
||||||
|
then if (maximum x) > (maximum y) then dirname' '\\' p else dirname' '/' p
|
||||||
|
else dirname' '\\' p
|
||||||
|
else dirname' '/' p
|
||||||
|
where
|
||||||
|
dirname' chara pa =
|
||||||
|
case reverse $ dropWhile (/= chara) $ reverse pa of
|
||||||
|
[] -> "."
|
||||||
|
pa' -> pa'
|
||||||
|
|
||||||
--
|
--
|
||||||
-- | basename : return the filename portion of a path
|
-- | basename : return the filename portion of a path
|
||||||
--
|
--
|
||||||
basename :: FilePath -> FilePath
|
basename :: FilePath -> FilePath
|
||||||
basename p = reverse $ takeWhile (/= '/') $ reverse p
|
basename p =
|
||||||
|
let x = findIndices (== '\\') p
|
||||||
|
y = findIndices (== '/') p
|
||||||
|
in
|
||||||
|
if not $ null x
|
||||||
|
then if not $ null y
|
||||||
|
then if (maximum x) > (maximum y) then basename' '\\' p else basename' '/' p
|
||||||
|
else basename' '\\' p
|
||||||
|
else basename' '/' p
|
||||||
|
where
|
||||||
|
basename' chara pa = reverse $ takeWhile (/= chara) $ reverse pa
|
||||||
|
|
||||||
--
|
--
|
||||||
-- drop suffix
|
-- drop suffix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user