Skip to content

Instantly share code, notes, and snippets.

@gf3
Created Feb 15, 2009
Embed
What would you like to do?
#!/usr/bin/env ruby -w
def find_caseinsensitive_duplicates(dir)
# INIT
conflicts = {}
# Load file list
files = Dir.entries(dir).collect{|f| f.downcase }
# Do yo thang!
files.each do |f|
files.each do |o|
if f == o
conflicts[f].nil? ? conflicts[f] = 1 : conflicts[f] += 1
end
end
end
conflicts = conflicts.delete_if{|w, o| o == 1}
if conflicts.empty?
puts "You're good to go! [#{dir}]"
else
puts "Conflicts found! [#{dir}]"
conflicts.sort.each do |c|
puts "conflict found on '#{c[0]}'"
end
puts "\n#{conflicts.length} conflict(s) in total."
end
end
# Main
if $0 == __FILE__
find_caseinsensitive_duplicates(ARGV[0] || Dir.pwd)
end
#!/usr/bin/env ruby -w
require "casechecker"
def recursively_find_caseinsensitive_duplicates(dir)
Dir.entries(dir).each do |file|
unless ["..", "."].include? file
new_path = File.join(dir, file)
recursively_find_caseinsensitive_duplicates(new_path) if File.directory? new_path
end
end
find_caseinsensitive_duplicates dir
end
# Main
if $0 == __FILE__
recursively_find_caseinsensitive_duplicates(ARGV[0] || Dir.pwd)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment