Last active
December 22, 2015 20:29
-
-
Save MgaMPKAy/6526584 to your computer and use it in GitHub Desktop.
List recursively all files under the giving path.
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
import System.Directory | |
-- For Hugs | |
(</>) :: FilePath -> FilePath -> FilePath | |
parent </> child = parent ++ "/" ++ child | |
fix f = let x = f x in x | |
when b act = if b then act else return () | |
-- Print file and directory recursively | |
main = fix (\f dir -> getDirectoryContents dir >>= (mapM_ (\d -> putStrLn d >> doesDirectoryExist (dir </> d) >>= flip when (f $ dir </> d))) . filter (`notElem` [".", ".."])) "/tmp" |
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
import Control.Applicative ((<$>)) | |
import System.Directory | |
-- Because Hugs doesn't have System.FilePath.(</>) | |
(</>) :: FilePath -> FilePath -> FilePath | |
parent </> child = parent ++ "/" ++ child | |
getDirectoryContents' :: FilePath -> IO [FilePath] | |
getDirectoryContents' dir = | |
filter (`notElem` [".", ".."]) <$> getDirectoryContents dir | |
recursiveFileList :: FilePath -> IO [FilePath] | |
recursiveFileList path = do | |
isDir <- doesDirectoryExist path | |
if not isDir | |
then do | |
isFile <- doesFileExist path | |
if isFile | |
then return [path] | |
else return [] | |
else do | |
subPaths <- map (path </>) <$> getDirectoryContents' path | |
subFiles <- mapM recursiveFileList subPaths | |
return $ concat subFiles | |
-- List files and directories: | |
-- return $ path : concat subFiles | |
main = recursiveFileList "/tmp/oldu/packages" >>= mapM_ putStrLn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment