1

我正在尝试找出一种使用 ruby​​zip 压缩文件的方法。我回滚到版本 0.9.9 因为新版本不起作用。下面是我试图测试它的代码

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

我收到一个错误,Errno::EACCES: Permission denied - /archive.zip20140716-17537-1t9f1pd。我想这与磁盘权限有关吗?我该如何解决?

4

1 回答 1

3

不要尝试将存档文件放在根文件系统中,因为您无权在那里写入:

- zipfile_name = "/archive.zip"
+ zipfile_name = "/temp/archive.zip"

希望能帮助到你。

于 2014-07-16T14:58:22.627 回答