Created
August 17, 2016 21:12
-
-
Save milothiesen/70e95951f72cadb0fd508cd2be7f01ca to your computer and use it in GitHub Desktop.
print out the names of unique files after scanning two directories
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/ruby | |
dir1 = ARGV[0] | |
dir2 = ARGV[1] | |
dir1_arry = [] | |
dir2_arry = [] | |
dir1_files_list = %x[find #{dir1} -name "*"].split("\n") | |
dir2_files_list = %x[find #{dir2} -name "*"].split("\n") | |
dir1_files_list.each do |filename| | |
filename.chomp! | |
dir1_arry << filename.split('/')[-1] | |
end | |
puts "the length of the first directory is #{dir1_arry.length}" | |
dir2_files_list.each do |filename| | |
filename.chomp! | |
dir2_arry << filename.split('/')[-1] | |
end | |
puts "the length of the second directory is #{dir2_arry.length}" | |
puts "THIS MARKS THE END OF LOOPING THROUGH EACH DIRECTORY" | |
if dir1_arry.uniq.sort == dir2_arry.uniq.sort | |
puts "there are no unique files, the files in each directory have the same name!" | |
else | |
unique_files = dir1_arry - dir2_arry | dir2_arry - dir1_arry | |
puts "the unique files are: " | |
unique_files.each { |file| puts file } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment