Ruby zip a folder - rubyzip
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' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found the issue, thanks:)