Skip to content

Instantly share code, notes, and snippets.

@yoon
Last active September 28, 2023 13:06
Show Gist options
  • Save yoon/8876313 to your computer and use it in GitHub Desktop.
Save yoon/8876313 to your computer and use it in GitHub Desktop.
zip a folder with rubyzip
require 'rubygems'
require 'zip'
archive_directory_path = ''
archive_zip_path = ''
Zip::File.open( archive_zip_path, Zip::File::CREATE ) do |zip_file|
Dir[ File.join( archive_directory_path, "**", "**" ) ].each do |file|
zip_file.add( file.sub( "#{ archive_directory_path }/", "" ), file )
end
end
@joshuapinter
Copy link

@dharshan's link is broken. Here's an updated version we're using, though:

Zip::File.open( archive_zip_path, Zip::File::CREATE ) do |zip_file|
  Dir[ File.join( archive_directory_path, "**", "**" ) ].each do |file|
    zip_file.add( file.sub( "#{ archive_directory_path }/", "" ), file )
  end
end

@yoon
Copy link
Author

yoon commented Jan 1, 2021

Kudos to @darshan and @joshuapinter

@dharshan
Copy link

dharshan commented Jan 1, 2021

@joshuapinter @yoon updated broken link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment