hcdu/app/Main.hs

30 lines
1.0 KiB
Haskell
Raw Normal View History

2023-10-12 13:01:36 +00:00
module Main where
2023-10-13 13:24:26 +00:00
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 )
2023-10-12 14:37:54 +00:00
2023-10-13 13:24:26 +00:00
listFiles :: FilePath -> IO [FilePath]
listFiles dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir
2023-10-12 14:37:54 +00:00
2023-10-13 13:24:26 +00:00
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
2023-10-12 14:37:54 +00:00
2023-10-12 13:01:36 +00:00
main :: IO ()
2023-10-12 14:37:54 +00:00
main = do
2023-10-13 13:24:26 +00:00
a <- getWorkingDirectory
print =<< getAllSubpaths a