Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get an inventory of the file system...
#!/usr/bin/env ruby
def compare_filesystem(previous, current)
previous_inventory = File.open(previous).readlines
current_inventory = File.open(current).readlines
# puts "The following files have been added:"
# puts current_inventory - previous_inventory
#
# puts ""
puts "The following files have been deleted:"
puts previous_inventory - current_inventory
# puts ""
# puts "The following files have not been changed:"
# current_inventory.each do |item|
# if previous_inventory.include?(item)
# puts item
# end
# end
end
def debug
counter = 0
puts "\nDebug:"
ARGV.each do |arg|
counter += 1
puts "\t[#{counter}] Argument: #{arg}"
end
puts ""
end
def invalid_arguments
#abort("Message goes here")
puts "\n\tUsage:"
puts "\t inventoryfs.rb --inventoryfs directory output_filename"
puts "\t *** if directory is blank we'll inventory the current directory ***"
puts "\tor:"
puts "\t inventoryfs.rb --comparefs previous_file current_file"
puts ""
exit
end
def inventory_filesystem(output)
File.open(output, 'w') do |line|
line.puts Dir.glob('**/*').each.sort
end
# line.puts Dir.glob('**/*').each { | file | file.downcase }.sort
end
arg = ARGV[0]
case arg
when '--inventoryfs'
if ARGV[1] == nil
invalid_arguments
elsif ARGV[2] == nil
inventory_filesystem(ARGV[1])
else
Dir.chdir(ARGV[1])
inventory_filesystem(ARGV[2])
end
when '--comparefs'
if ARGV[1] != nil and ARGV[2] != nil
compare_filesystem(ARGV[1], ARGV[2])
else
invalid_arguments
end
when '--debug'
debug
else
invalid_arguments
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.