Skip to content

Instantly share code, notes, and snippets.

@simonharrer
Created September 16, 2015 15:21
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 simonharrer/088b6e64c94cd8dc49ae to your computer and use it in GitHub Desktop.
Save simonharrer/088b6e64c94cd8dc49ae to your computer and use it in GitHub Desktop.
Finds duplicate files in sibling folders
result = {}
Dir.glob("*").each do |dir|
result[dir] = Dir.glob("#{dir}/**/*").to_a.select {|p| File.file?(p)}.map {|p| p[dir.length..-1]}
end
puts "#{result.count} dirs found"
result.each do |key, value|
result.each do |key2, value2|
if(key != key2)
dups = value & value2
# puts "#{key} and #{key2}: #{dups}" unless dups.empty?
end
end
end
puts "invers"
result_inv = {}
result.each do |key, value|
value.each do |v|
unless(result_inv.key? (v))
result_inv[v] = []
end
result_inv[v] << key
end
end
result_inv.each do |key, value|
puts "#{key}: #{value}" if value.size > 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment