Created
January 6, 2014 19:03
-
-
Save pentikos/8287878 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
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