33 lines
838 B
Haskell
33 lines
838 B
Haskell
module Files (
|
|
File(..)
|
|
, absolute
|
|
, absoluteLink
|
|
, filePath
|
|
, find
|
|
) where
|
|
|
|
import System.Exit (die)
|
|
import System.Directory (doesDirectoryExist, doesFileExist, listDirectory, makeAbsolute)
|
|
import System.FilePath ((</>))
|
|
|
|
data File = File FilePath | Dir FilePath
|
|
|
|
absolute :: File -> IO (FilePath)
|
|
absolute file = filePath file >>= makeAbsolute
|
|
|
|
absoluteLink :: FilePath -> FilePath
|
|
absoluteLink ('.':path) = path
|
|
absoluteLink path = "/" </> path
|
|
|
|
filePath :: File -> IO FilePath
|
|
filePath (File path) = do
|
|
bool <- doesFileExist path
|
|
if bool then return path else die $ path ++ ": no such file"
|
|
filePath (Dir path) = do
|
|
bool <- doesDirectoryExist path
|
|
if bool then return path else die $ path ++ ": no such directory"
|
|
|
|
find :: FilePath -> IO [FilePath]
|
|
find path =
|
|
fmap (path </>) <$> listDirectory path
|