File Decompression

File Decompression


This script shows you the basics of decompressing a file. The rubyzip library does all of the work for you. On a standard Unix-like system, you would have to manually unzip the file, carry out your task, and then re-compress the file. With rubyzip, you can work with files in an archive using one seamless library. This script completely decompresses an archive into the user-specified directory.

The Code

 require 'zip/zip'
 require 'fileutils'

 unless ARGV[0]
     puts "Usage: ruby decompress.rb <>"
     puts "Example: ruby decompress.rb"

 archive = ARGV[0].chomp

 if File.exists?(archive) ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.