(•ิ_•ิ)?

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

View File

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