Created
January 29, 2012 13:40
-
-
Save juriglx/1698873 to your computer and use it in GitHub Desktop.
removes duplicate files, keeps the file with the longer filename
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 -w | |
require 'rubygems' | |
require 'digest/md5' | |
ARGV.each do |dir| | |
hf = {} | |
Dir["#{dir}/*"].each do |file| | |
h = Digest::MD5.hexdigest(File.read(file)) | |
if hf[h].nil? | |
hf[h] = file | |
next | |
end | |
if File.basename(hf[h]).length > File.basename(file).length | |
puts "deleting #{file}" | |
File.delete file | |
else | |
puts "deleting #{hf[h]}" | |
File.delete hf[h] | |
hf[h] = file | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment