Created
January 14, 2009 09:15
-
-
Save tbalthazar/46848 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
# http://discuss.joyent.com/viewtopic.php?id=9043 | |
require 'zip/zipfilesystem' | |
# source should be a zip file. | |
# target should be a directory to output the contents to. | |
def unzip_file(source, target) | |
# Create the target directory. | |
# We'll ignore the error scenario where | |
begin | |
Dir.mkdir(target) unless File.exists? target | |
end | |
Zip::ZipFile.open(source) do |zipfile| | |
dir = zipfile.dir | |
dir.entries('.').each do |entry| | |
zipfile.extract(entry, "#{target}/#{entry}") | |
end | |
end | |
rescue Zip::ZipDestinationFileExistsError => ex | |
# I'm going to ignore this and just overwrite the files. | |
rescue => ex | |
puts ex | |
end | |
unzip_file('/home/styrmis/workspace/ruby/unzip/test.zip', '/home/styrmis/workspace/ruby/unzip/target') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment