Reputation: 189
I'm just wondering if I can use any specific method from System.Directory package or something to get a list of all nested directories given a specified path. I have not found any appropriate function so I came up with something like this:
getDirList :: FilePath -> IO [FilePath]
getDirList dir = do
contents <- getDirectoryContents dir
all <- mapM (return . (dir </>)) $ filter (\f -> f /= "." && f /= "..") contents
dirs <- filterM doesDirectoryExist all
dirs' <- mapM getDirList dirs
return (dir : concat dirs')
May be I have been missing something really simple? Can anybody suggest? Thank you.
Upvotes: 1
Views: 153
Reputation: 553
If it's ok to use filemanip package:
import System.FilePath.Find
getDirList dir = find always (fileType ==? Directory) dir
Upvotes: 1