2015-03-04 20:48:21 +00:00
|
|
|
module Dir (
|
|
|
|
module Dir
|
|
|
|
, getCurrentDirectory
|
|
|
|
, (</>)
|
|
|
|
) where
|
2013-02-12 05:06:22 +00:00
|
|
|
|
2013-02-12 07:24:33 +00:00
|
|
|
import Control.Exception as E
|
2013-09-20 02:22:56 +00:00
|
|
|
import Data.List (isPrefixOf)
|
|
|
|
import System.Directory
|
2015-03-04 20:48:21 +00:00
|
|
|
import System.FilePath (addTrailingPathSeparator,(</>))
|
|
|
|
|
|
|
|
|
2013-02-12 05:06:22 +00:00
|
|
|
|
2013-03-05 01:22:33 +00:00
|
|
|
withDirectory_ :: FilePath -> IO a -> IO a
|
|
|
|
withDirectory_ dir action = bracket getCurrentDirectory
|
2013-03-05 01:44:17 +00:00
|
|
|
setCurrentDirectory
|
|
|
|
(\_ -> setCurrentDirectory dir >> action)
|
2013-03-05 01:22:33 +00:00
|
|
|
|
|
|
|
withDirectory :: FilePath -> (FilePath -> IO a) -> IO a
|
|
|
|
withDirectory dir action = bracket getCurrentDirectory
|
|
|
|
setCurrentDirectory
|
|
|
|
(\d -> setCurrentDirectory dir >> action d)
|
2013-09-20 02:22:56 +00:00
|
|
|
|
|
|
|
toRelativeDir :: FilePath -> FilePath -> FilePath
|
|
|
|
toRelativeDir dir file
|
|
|
|
| dir' `isPrefixOf` file = drop len file
|
|
|
|
| otherwise = file
|
|
|
|
where
|
|
|
|
dir' = addTrailingPathSeparator dir
|
|
|
|
len = length dir'
|