Skip to content

Instantly share code, notes, and snippets.

@dharshan
Last active Jan 1, 2021
Embed
What would you like to do?
Ruby zip a folder - rubyzip
require 'zip'
input_directory = '' # directory to be zipped
zipfile_name = '' # zip-file name
# zip a folder with only files (NO SUB FOLDERS)
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
Dir[File.join(input_directory, '*')].each do |file|
zipfile.add(file.sub(input_directory, ''), file)
end
end
# zip a folder with files and subfolders
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
Dir["#{input_directory}/**/**"].each do |file|
zipfile.add(file.sub(input_directory + '/', ''), file)
end
end
@romanbaitaliuk
Copy link

romanbaitaliuk commented Jun 23, 2020

Found the issue, thanks:)

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