Created
November 18, 2009 01:18
-
-
Save ldunn/237465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment