Created
June 16, 2012 05:39
-
-
Save emctoo/2940095 to your computer and use it in GitHub Desktop.
recursive list contents of a directory
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
-- from Real World Haskell, Chapter 9 | |
module RecursiveContents (getRecursiveContents) where | |
import Control.Monad (forM) | |
import System.Directory (doesDirectoryExist, getDirectoryContents, getCurrentDirectory) | |
import System.FilePath ((</>)) | |
getRecursiveContents :: FilePath -> IO [FilePath] | |
getRecursiveContents topdir = do | |
names <- getDirectoryContents topdir | |
let properNames = filter (`notElem` [".", ".."]) names | |
paths <- forM properNames $ \name -> do | |
let path = topdir </> name | |
isDirectory <- doesDirectoryExist path | |
if isDirectory then getRecursiveContents path else return [path] | |
return (concat paths) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment