Skip to content

Instantly share code, notes, and snippets.

@aya-eiya
Created February 20, 2012 01:54
Show Gist options
  • Save aya-eiya/1867171 to your computer and use it in GitHub Desktop.
Save aya-eiya/1867171 to your computer and use it in GitHub Desktop.
指定したディレクトリを再帰的に探索して末端のパスのリストを返します。#haskell
module Main where
import Directory
import Data.List
import System
main = do [ root ] <- getArgs
cnt <- getTerminals [] root
getTerminals root path
= do b <- doesDirectoryExist pth
c <- doesFileExist pth
case (b,c,null path) of
(False,False,_) -> error $ pth ++ " was not found."
(True,_,False) -> _subGetTerminals
_ -> return [pth]
where
pth = if null root then path else root ++ "/" ++ path
_subGetTerminals
= do b <- getDirectoryContents pth
c <- mapM (getTerminals pth) (b \\ [".",".."])
return $ concat c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment