File size distribution: Difference between revisions

Content added Content deleted
(Add Factor)
m (→‎{{header|Haskell}}: optimize file collection)
Line 441: Line 441:
import GHC.Conc (getNumProcessors)
import GHC.Conc (getNumProcessors)
import System.Directory (doesDirectoryExist, doesFileExist,
import System.Directory (doesDirectoryExist, doesFileExist,
getDirectoryContents,
listDirectory,
pathIsSymbolicLink)
pathIsSymbolicLink)
import System.Environment (getArgs)
import System.Environment (getArgs)
Line 562: Line 562:
pure []
pure []
where
where
tryCollect = do
tryCollect = (fmap (folderPath </>) <$> listDirectory folderPath) >>= mapM f
where
contents <- fmap (folderPath </>) <$> getDirectoryContents folderPath
files <- filterM doesFileExist contents
f p = do
folders <- drop 2 <$> filterM doesDirectoryExist contents
isFolder <- doesDirectoryExist p
if isFolder then
items <- mapM (\f -> File f <$> withFile f ReadMode hFileSize) files
pure $ items <> fmap Folder folders
pure $ Folder p
else do
size <- withFile p ReadMode hFileSize
pure $ File p size


parallelItemCollector :: FilePath -> IO [Item]
parallelItemCollector :: FilePath -> IO [Item]