Advertisement
Guest User

Untitled

a guest
May 27th, 2016
60
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. process :: FilePath -> FilePath -> IO [String]
  26. process path f = do
  27. let full_path = path </> f
  28. is_dir <- doesDirectoryExist full_path
  29. if is_dir
  30. then listFiles full_path
  31. else strFile (full_path, fsize full_path)
  32.  
  33. diff :: [String] -> String -> [String] -> String -> [String]
  34. diff f1content f1name f2content f2name = do
  35. let another_dir = map (\f -> myTrim f f2name) f2content
  36. [f1 | f1 <- f1content, not $ myTrim f1 f1name `elem` another_dir]
  37. where
  38. myTrim s t = drop ((length t) + 4) s
  39.  
  40. main = do
  41. first <- getLine
  42. second <- getLine
  43.  
  44. f_files <- process "." first
  45. s_files <- process "." second
  46.  
  47. putStrLn ""
  48. putStrLn $ "Unique files from " ++ first
  49. mapM_ putStrLn $ diff f_files first s_files second
  50.  
  51. putStrLn ""
  52. putStrLn $ "Unique files from " ++ second
  53. mapM_ putStrLn $ diff s_files second f_files first
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement