Created
August 28, 2015 00:33
-
-
Save afonsomatos/35920703efb662c8078a to your computer and use it in GitHub Desktop.
Get files recursively inside directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module System.Directory.Tree where | |
import System.Directory ( doesFileExist, getDirectoryContents ) | |
data DirTree = Directory String [DirTree] | |
| File String | |
deriving (Show, Eq) | |
getDirTree :: FilePath -> IO [DirTree] | |
getDirTree path = getDirectoryContents path | |
>>= mapM dirOrFile | |
. filter (`notElem` [".", ".."]) | |
where dirOrFile n = let loc = path ++ "/" ++ n | |
tree True = fmap (Directory n) $ getDirTree loc | |
tree False = return $ File n | |
in doesFileExist loc | |
>>= tree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment