Created
February 20, 2012 01:54
-
-
Save aya-eiya/1867171 to your computer and use it in GitHub Desktop.
指定したディレクトリを再帰的に探索して末端のパスのリストを返します。#haskell
This file contains 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
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