Advertisement
Guest User

Untitled

a guest
May 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. module Main where
  2.  
  3. import System.IO
  4. import System.Directory
  5. import System.FilePath
  6. import Control.Monad
  7.  
  8. fsize :: FilePath -> IO Integer
  9. fsize path = withFile path ReadMode hFileSize
  10.  
  11. strFile :: (FilePath, IO Integer) -> IO [String]
  12. strFile file = do
  13. let file_path = fst file
  14. file_size <- snd file
  15. return [show file_path ++ " " ++ show file_size]
  16.  
  17. listFiles :: FilePath -> IO [String]
  18. listFiles path = do
  19. t <- getDirectoryContents path
  20. let dir = filter(`notElem` [".", ".."]) t
  21. files <- mapM (\f -> process path f) dir
  22. return $ concat files
  23.  
  24.  
  25.  
  26. process :: FilePath -> FilePath -> IO [String]
  27. process path f = do
  28. let full_path = path </> f
  29. is_dir <- doesDirectoryExist full_path
  30. if is_dir
  31. then listFiles full_path
  32. else strFile (full_path, fsize full_path)
  33.  
  34. diff :: [String] -> String -> [String] -> String -> [String]
  35. diff folder1 f1name folder2 f2name = do
  36. let dir2 = map (\f -> myTrim f f2name) folder2
  37. let res = [f1 | f1 <- folder1, not $ myTrim f1 f1name `elem` dir2]
  38. res
  39. where
  40. myTrim s t = drop ((length t) + 4) s
  41.  
  42. main = do
  43. first <- getLine
  44. second <- getLine
  45.  
  46. f_files <- process "." first
  47. s_files <- process "." second
  48.  
  49. putStrLn ""
  50. putStrLn $ "Unique files from " ++ first
  51. mapM_ putStrLn $ diff f_files first s_files second
  52.  
  53. putStrLn ""
  54. putStrLn $ "Unique files from " ++ second
  55. mapM_ putStrLn $ diff s_files second f_files first
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement