unzip

Unzipping files with ruby

The author wanted to find the right way of doing this in ruby. I just wanted it to work, so this is good enough. Thanks, Mark Needham!

require 'rubygems'
require 'zip/zip'
 
def unzip_file (file, destination)
  Zip::ZipFile.open(file) { |zip_file|
   zip_file.each { |f|
     f_path=File.join(destination, f.name)
     FileUtils.mkdir_p(File.dirname(f_path))
     zip_file.extract(f, f_path) unless File.exist?(f_path)
   }
  }
end

http://www.markhneedham.com/blog/2008/10/02/ruby-unzipping-a-file-using-...

Syndicate content