I'm trying to figure out a way to zip files using rubyzip. I rolled back to version 0.9.9 because the new version didn't work. below is the code I'm trying to test it with
require 'rubygems'
require 'zip/zip'
folder = "/temp"
input_filenames = ['COKE.csv', 'GM.csv', 'GOOG.csv']
zipfile_name = "/archive.zip"
Zip::ZipFile.open(zipfile_name, Zip::ZipFile::CREATE) do |zipfile|
input_filenames.each do |filename|
# Two arguments:
# - The name of the file as it will appear in the archive
# - The original file, including the path to find it
zipfile.add("archive", folder + '/' + filename)
end
zipfile.get_output_stream("myFile") { |os| os.write "myFile contains just this" }
end
I get an error though, Errno::EACCES: Permission denied - /archive.zip20140716-17537-1t9f1pd. I guess this is something to do with disc permissions? how can i fix it?
Don’t try to put archive file in the root filesystem, since you don’t have rights to write there:
- zipfile_name = "/archive.zip"
+ zipfile_name = "/temp/archive.zip"
Hope it helps.