【问题标题】:permission denied when using rubyzip使用 ruby​​zip 时权限被拒绝
【发布时间】:2014-07-16 14:14:57
【问题描述】:

我正在尝试找出一种使用 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。我想这与磁盘权限有关吗?我该如何解决?

【问题讨论】:

    标签: ruby rubyzip


    【解决方案1】:

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

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

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多