Skip to content

Instantly share code, notes, and snippets.

@milothiesen
Created August 17, 2016 21:12
Show Gist options
  • Save milothiesen/70e95951f72cadb0fd508cd2be7f01ca to your computer and use it in GitHub Desktop.
Save milothiesen/70e95951f72cadb0fd508cd2be7f01ca to your computer and use it in GitHub Desktop.
print out the names of unique files after scanning two directories
#!/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