Created
January 1, 2015 07:24
-
-
Save chadaustin/f98dca810d64f32ad65f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
walk :: FilePath -> ((FilePath, [FilePath], [FilePath]) -> IO ()) -> IO () | |
walk root action = do | |
entries <- Directory.getDirectoryContents root | |
directories <- newIORef [] | |
files <- newIORef [] | |
forM_ entries $ \entry -> do | |
let fullPath = combine root entry | |
isFile <- Directory.doesFileExist fullPath | |
if isFile then | |
modifyIORef files (entry:) | |
else do | |
when (entry /= "." && entry /= "..") $ do | |
isDirectory <- Directory.doesDirectoryExist fullPath | |
when isDirectory $ modifyIORef directories (entry:) | |
ds <- readIORef directories | |
fs <- readIORef files | |
action (root, sort ds, sort fs) | |
forM_ ds $ \dir -> | |
walk (combine root dir) action |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment