Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'digest/md5'
- require 'find'
- @hashfun = Digest::MD5.new
- @files = Hash.new()
- @filenames = Hash.new()
- @hashes = Array.[]
- def hashsum(filename)
- file = File.new(filename)
- contents = file.read()
- return @hashfun.hexdigest(contents)
- end
- def checkdupe(filename)
- filehash = @files[filename]
- for hash in @hashes
- if filehash == hash
- puts filename + " and " + @filenames[hash] + " are duplicate."
- end
- end
- end
- puts "Enter dir name to search:"
- dir = gets.strip()
- dirs = [dir]
- for dir in dirs
- Find.find(dir) do |path|
- if FileTest.directory?(path)
- else
- hash = hashsum(path)
- @files[path] = hash
- @filenames[hash] = path
- checkdupe(path)
- @hashes << hash
- # puts @files[path]
- end
- end
- end
Add Comment
Please, Sign In to add comment