Created
December 14, 2012 03:02
-
-
Save JGallardo/4282333 to your computer and use it in GitHub Desktop.
Ruby script to decompress files.
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 'zip/zip' | |
require 'fileutils' | |
unless ARGV[0] | |
puts "Usage: ruby decompress.rb <zipfilename.zip>" | |
puts "Example: ruby decompress.rb myfile.zip" | |
exit | |
end | |
archive = ARGV[0].chomp | |
if File.exists?(archive) | |
print "Enter path to save files to (\'.\' for same directory): " | |
extract_dir = gets.chomp | |
begin | |
Zip::ZipFile::open(archive) do |zipfile| | |
zipfile.each do |f| | |
path = File.join(extract_dir, f.name) | |
FileUtils.mkdir_p(File.dirname(path)) | |
zipfile.extract(f, path) | |
end | |
end | |
rescue Exception => e | |
puts e | |
end | |
else | |
puts "An error occurred during decompression: \n #{e}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment