Skip to content

Instantly share code, notes, and snippets.

@romanbsd
Created March 9, 2024 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanbsd/d5247a5890fb07f26da4e713229ab555 to your computer and use it in GitHub Desktop.
Save romanbsd/d5247a5890fb07f26da4e713229ab555 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'digest'
all = Hash.new
Dir["*.jpg"].each do |file|
md5 = Digest::MD5.hexdigest(IO.read(file))
ary = all.fetch(md5, [])
ary << file
all[md5] = ary
end
all.each do |k,v|
if v.size > 1
puts("#{k} has #{v.size} entries: #{v}")
while v.size > 1
found = v.find { |f| f.include?("copy") }
break unless found
File.unlink(found)
v.delete(found)
puts "Removing #{found}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment