Skip to content

Instantly share code, notes, and snippets.

@JGallardo
Created December 14, 2012 03:02
Show Gist options
  • Save JGallardo/4282333 to your computer and use it in GitHub Desktop.
Save JGallardo/4282333 to your computer and use it in GitHub Desktop.
Ruby script to decompress files.
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