Skip to content

Instantly share code, notes, and snippets.

@FranklinChen
Created October 20, 2015 23:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FranklinChen/133cb61af931a08bbe20 to your computer and use it in GitHub Desktop.
Save FranklinChen/133cb61af931a08bbe20 to your computer and use it in GitHub Desktop.
-- | 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