Guest User

Untitled

a guest
Apr 24th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. require 'digest/md5'
  3. require 'find'
  4.  
  5. @hashfun = Digest::MD5.new
  6. @files = Hash.new()
  7. @filenames = Hash.new()
  8. @hashes = Array.[]
  9. def hashsum(filename)
  10. file = File.new(filename)
  11. contents = file.read()
  12. return @hashfun.hexdigest(contents)
  13. end
  14.  
  15.  
  16. def checkdupe(filename)
  17. filehash = @files[filename]
  18. for hash in @hashes
  19. if filehash == hash
  20. puts filename + " and " + @filenames[hash] + " are duplicate."
  21. end
  22. end
  23. end
  24.  
  25. puts "Enter dir name to search:"
  26. dir = gets.strip()
  27.  
  28. dirs = [dir]
  29. for dir in dirs
  30. Find.find(dir) do |path|
  31. if FileTest.directory?(path)
  32. else
  33. hash = hashsum(path)
  34. @files[path] = hash
  35. @filenames[hash] = path
  36. checkdupe(path)
  37. @hashes << hash
  38. # puts @files[path]
  39. end
  40. end
  41. end
Add Comment
Please, Sign In to add comment