Skip to content

Instantly share code, notes, and snippets.

@ashchan
Created August 21, 2008 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ashchan/6510 to your computer and use it in GitHub Desktop.
Save ashchan/6510 to your computer and use it in GitHub Desktop.
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