module Main where import System.Posix.Types () import System.Posix.Files () import System.Posix.Directory ( getWorkingDirectory ) import System.Directory ( pathIsSymbolicLink, doesFileExist, getFileSize, doesDirectoryExist ) import System.Environment () import Data.Functor ( (<&>) ) import Control.Monad ( (<=<), filterM ) import System.Directory.Extra ( listContents ) listFiles :: FilePath -> IO [FilePath] listFiles dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir listDirectories :: FilePath -> IO [FilePath] listDirectories dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesDirectoryExist =<< listContents dir getAllSubpaths :: FilePath -> IO [(FilePath, Integer)] getAllSubpaths x = do sub <- listDirectories x subFiles <- mapM getAllSubpaths sub local <- listFiles x >>= (\y -> mapM getFileSize y <&> zip y) return $ local ++ concat subFiles main :: IO () main = do a <- getWorkingDirectory print =<< getAllSubpaths a