Last active
December 21, 2015 05:18
-
-
Save fujimura/6255790 to your computer and use it in GitHub Desktop.
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
import Control.Applicative ((<$>)) | |
import Control.Monad | |
import System.Directory (doesDirectoryExist, doesFileExist, | |
getCurrentDirectory, getDirectoryContents) | |
entries :: FilePath -> IO [FilePath] | |
entries path = do | |
contents <- getDirectoryContents path | |
files <- filterM doesFileExist' contents | |
directories <- filter isSubDirectory <$> filterM doesDirectoryExist' contents | |
subdirEntries <- mapM entries (map expandPath directories) | |
return $ files ++ concat subdirEntries | |
where | |
expandPath x = path ++ "/" ++ x | |
doesFileExist' = doesFileExist . expandPath | |
doesDirectoryExist' = doesDirectoryExist . expandPath | |
isSubDirectory :: FilePath -> Bool | |
isSubDirectory "." = False | |
isSubDirectory ".." = False | |
isSubDirectory _ = True | |
main :: IO () | |
main = do | |
p <- getCurrentDirectory | |
contents <- entries p | |
forM_ contents putStrLn |
Author
fujimura
commented
Aug 17, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment