使用rubyzip时权限被拒绝

时间:2014-07-16 14:14:57

标签: ruby rubyzip

我正试图找出一种使用rubyzip压缩文件的方法。我回滚到版本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。我想这与光盘权限有关?我该如何解决?

1 个答案:

答案 0 :(得分:3)

不要试图将归档文件放在根文件系统中,因为你没有权限在那里写:

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

希望它有所帮助。