Skip to content

Instantly share code, notes, and snippets.

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 rdp/d706df3c4e87ff93a398 to your computer and use it in GitHub Desktop.
Save rdp/d706df3c4e87ff93a398 to your computer and use it in GitHub Desktop.
if ARGV.length != 2
puts "syntax: dir_that_has_files_that_should_be_duplicated dir_that_should_have_those_files"
exit 1
end
def all_files_in_dir dir
all_in = {}
Dir[File.expand_path(dir) + "/**/*"].each{|f| # need expand path or in windows Dir["a\b/*"] failz <sigh>
if File.file? f
filename = File.basename(f)
file_size = File.size(f)
key = "#{filename}_#{file_size}" # XX md5?
all_in[key] ||= [] # accomodate duplicates
all_in[key] << File.expand_path(f)
end
}
all_in
end
files_wanted = all_files_in_dir(ARGV[0])
files_there = all_files_in_dir(ARGV[1])
p "searching for #{files_wanted.length} files among #{files_there.length}..."
desired_but_not_found = files_wanted.keys - files_there.keys
for bad in desired_but_not_found
puts "unable to find #{bad} #{files_wanted[bad]} anywhere"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment