Skip to content

Instantly share code, notes, and snippets.

@pentikos
Created January 6, 2014 19:03
Show Gist options
  • Save pentikos/8287878 to your computer and use it in GitHub Desktop.
Save pentikos/8287878 to your computer and use it in GitHub Desktop.
require 'optparse'
require 'find'
OPTIONS = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: unpack.rb <options>"
opts.on("-s [DIR]", "--source", "What directory should be scanned") { |dir| OPTIONS[:source] = dir }
opts.on("-d [DIR]", "--destination", "Where the extracted files should go") { |dir| OPTIONS[:destination] = dir }
end
parser.parse!
required_arguments = [:source, :destination]
unless required_arguments.all? { |arg| OPTIONS[arg] != nil }
puts parser
exit(1)
end
OPTIONS[:extension] = ".rar"
def scan_directory(directory)
Find.find(directory) do |f|
if File.extname(f) == OPTIONS[:extension]
puts "Unpacking #{File.basename(f)}"
`unrar e #{f} #{OPTIONS[:destination]}`
end
end
end
scan_directory(OPTIONS[:source])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment