Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- import System.IO
- import System.Directory
- import System.FilePath
- import Control.Monad
- fsize :: FilePath -> IO Integer
- fsize path = withFile path ReadMode hFileSize
- strFile :: (FilePath, IO Integer) -> IO [String]
- strFile file = do
- let file_path = fst file
- file_size <- snd file
- return [show file_path ++ " " ++ show file_size]
- listFiles :: FilePath -> IO [String]
- listFiles path = do
- t <- getDirectoryContents path
- let dir = filter(`notElem` [".", ".."]) t
- files <- mapM (\f -> process path f) dir
- return $ concat files
- process :: FilePath -> FilePath -> IO [String]
- process path f = do
- let full_path = path </> f
- is_dir <- doesDirectoryExist full_path
- if is_dir
- then listFiles full_path
- else strFile (full_path, fsize full_path)
- diff :: [String] -> String -> [String] -> String -> [String]
- diff folder1 f1name folder2 f2name = do
- let dir2 = map (\f -> myTrim f f2name) folder2
- let res = [f1 | f1 <- folder1, not $ myTrim f1 f1name `elem` dir2]
- res
- where
- myTrim s t = drop ((length t) + 4) s
- main = do
- first <- getLine
- second <- getLine
- f_files <- process "." first
- s_files <- process "." second
- putStrLn ""
- putStrLn $ "Unique files from " ++ first
- mapM_ putStrLn $ diff f_files first s_files second
- putStrLn ""
- putStrLn $ "Unique files from " ++ second
- mapM_ putStrLn $ diff s_files second f_files first
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement