Created
February 15, 2009 03:17
-
-
Save gf3/64582 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 -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 |
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 -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