Skip to content

Instantly share code, notes, and snippets.

@juriglx
Created January 29, 2012 13:40
Show Gist options
  • Save juriglx/1698873 to your computer and use it in GitHub Desktop.
Save juriglx/1698873 to your computer and use it in GitHub Desktop.
removes duplicate files, keeps the file with the longer filename
#!/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