-
-
Save cjweeg/1502383 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# ARGV[0] should point to the "Raw" directory | |
# ARGV[1] should point to the "Enhanced" directory | |
if !ARGV[0] or !ARGV[1] | |
puts "You must specify the raw and enhanced directories. Try again!" | |
exit | |
end | |
# first we find the full path of the arguments in case we're only given | |
# partial paths. | |
raw_input_file_path = File.expand_path(ARGV[0]) | |
enhanced_input_file_path = File.expand_path(ARGV[1]) | |
# we check to make sure that the specified directories actually exist | |
if !File.exist?(raw_input_file_path) && File.exist?(enhanced_input_file_path) | |
puts "Raw directory does not exist. Try again!" | |
exit | |
end | |
if File.exist?(raw_input_file_path) && !File.exist?(enhanced_input_file_path) | |
puts "Enhanced directory does not exist. Try again!" | |
exit | |
end | |
if !File.exist?(raw_input_file_path) && !File.exist?(enhanced_input_file_path) | |
puts "Raw directory does not exist" | |
puts "Enhanced directory does not exist, either. Try again!" | |
exit | |
end | |
# next we'll join the raw input file path with the asterisk, find all the | |
# filepaths, and then map the filepath to file base names. | |
enhanced_files = Dir.glob(File.join(raw_input_file_path, '*')).map do |filepath| | |
File.basename(filepath) | |
end | |
raw_files = Dir.glob(File.join(enhanced_input_file_path, '*')).map do |filepath| | |
File.basename(filepath) | |
end | |
# now we calculate if there are any unique files | |
enhanced_dir_unique_files = raw_files - enhanced_files | |
raw_dir_unique_files = enhanced_files - raw_files | |
# now we compare both directories, looking for 1 of 3 scenarios | |
# 1: No difference between contained files (if any) | |
# 2: Unique files exist in the Raw directory | |
# 3: Unique files exist in the Enhanced directory | |
if raw_dir_unique_files.empty? and enhanced_dir_unique_files.empty? | |
puts "No unique files." | |
end | |
if !raw_dir_unique_files.empty? | |
puts "One or more unique files exist in the RAW directory" | |
puts raw_dir_unique_files | |
end | |
if !enhanced_dir_unique_files.empty? | |
puts "One or more unique files exist in the ENHANCED directory" | |
puts enhanced_dir_unique_files | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment