Created
March 9, 2024 13:13
-
-
Save romanbsd/d5247a5890fb07f26da4e713229ab555 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/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