Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- | http://stackoverflow.com/questions/14259229/streaming-recursive-descent-of-a-directory-in-haskell/14261710#14261710
--
-- Updated to latest Pipes 4.
module Main where
import Pipes
import qualified Pipes.Prelude as P
import Control.Monad (forM_)
import System.Directory (doesDirectoryExist, getDirectoryContents)
import System.Environment (getArgs)
import System.FilePath ((</>))
getRecursiveContents :: FilePath -> Producer FilePath IO ()
getRecursiveContents topPath = do
names <- lift $ getDirectoryContents topPath
let properNames = filter (`notElem` [".", ".."]) names
forM_ properNames $ \name -> do
let path = topPath </> name
isDirectory <- lift $ doesDirectoryExist path
if isDirectory
then getRecursiveContents path
else yield path
main :: IO ()
main = do
[path] <- getArgs
runEffect $
getRecursiveContents path
>-> P.map ("Found file " ++)
>-> P.stdoutLn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.