Created
August 21, 2008 05:43
-
-
Save ashchan/6510 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
require 'zip/zip' | |
# zip files | |
Dir.chdir(parent_directory) | |
zipfile = directory + ".zip" | |
return false if File.exist?(zipfile) | |
Zip::ZipFile::open(zipfile, true) do |zf| | |
Dir["#{directory}/**/*"].each { |f| zf.add(f, f) } | |
zf.close | |
end | |
# unzip files | |
begin | |
Zip::ZipFile::open(zipfile) do |zf| | |
zf.each do |e| | |
fpath = File.join(local_directory, e.name) | |
FileUtils.mkdir_p(File.dirname(fpath)) | |
zf.extract(e, fpath) | |
end | |
end | |
rescue Zip::ZipDestinationFileExistsError => e | |
#? | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment