(•ิ_•ิ)?

This commit is contained in:
pingu 2023-10-13 15:24:26 +02:00
parent 45f6086c69
commit bdd857e491
2 changed files with 25 additions and 8 deletions

View File

@ -1,14 +1,29 @@
module Main where module Main where
import System.PosixCompat.Types import System.Posix.Types ()
import System.PosixCompat.Files 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 )
getFileSize :: FilePath -> IO FileOffset listFiles :: FilePath -> IO [FilePath]
getFileSize = (fileSize <$>) . getFileStatus listFiles dir = filterM ((return . not) <=< pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir
getFolderSize :: FilePath -> IO FileOffset listDirectories :: FilePath -> IO [FilePath]
getFolderSize path = undefined 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 :: IO ()
main = do main = do
putStrLn "Hello, Haskell!" a <- getWorkingDirectory
print =<< getAllSubpaths a

View File

@ -71,7 +71,9 @@ executable hcdu
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base ^>=4.17.1.0 build-depends: base ^>=4.17.1.0
, brick >= 1.9 , brick >= 1.9
, unix-compat >= 0.7 , unix
, extra
, directory
-- Directories containing source files. -- Directories containing source files.
hs-source-dirs: app hs-source-dirs: app