【问题标题】:Unzip a .zip file to a specific folder using :zip module使用 :zip 模块将 .zip 文件解压缩到特定文件夹
【发布时间】:2018-10-21 01:16:04
【问题描述】:

我正在尝试将 .zip 文件解压缩到特定文件夹路径:

http://erlang.org/doc/man/zip.html#unzip-1

:zip.unzip(zip_path, {cwd: "/tmp/test-extracted/"})

** (SyntaxError) test.exs:18: syntax error before: cwd
    (elixir) lib/code.ex:677: Code.require_file/2

【问题讨论】:

    标签: path erlang directory unzip


    【解决方案1】:

    像这样:

    :zip.unzip(String.to_charlist(zip_path), cwd: "/tmp/test-extracted/")
    

    【讨论】:

      【解决方案2】:

      这里有几个语法错误。

      1) 要调用模块中定义的函数,请使用Module:Function(Arguments)

      zip:unzip(Zipfile).  % not zip.unzip()
      

      2) 以小写字符开头的标记称为atoms,这只是一些文字。 unzip/2 的第一个参数应该使用变量。

      Zipfile = "/path/to/your/zipfile.zip".
      zip:unzip(Zipfile).
      

      3)对于unzip/2的第二个参数,我们来看看如何理解你发布的文档:

      unzip(Archive, Options) -> RetValue  
      

      这是函数签名:两个变量参数和一个返回值

      Archive = file:name() | binary()
      

      第一个参数的类型应该是file:name() 或二进制

      Options = [Option]
      

      Options 参数应该是一个列表。

      Option = {file_list, FileList} |
          keep_old_files |
          verbose |
          memory |
          {file_filter, FileFilter} |
          {cwd, CWD} 
      

      列表有多种形式,包括你需要的:{cwd, CWD},它是一个元组,它的第一个元素是原子cwd

      我们现在掌握了正确调用zip:unzip/2的所有知识:

      Zipfile = "/path/to/your/zipfile.zip".
      MyCwd = "/path/to/working_dir/".
      zip:unzip(ZipPath, [{cwd, MyCwd}]). 
      

      【讨论】:

      • 你的整个答案都是错误的,语法错误几乎无处不在。
      猜你喜欢
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2021-05-16
      相关资源
      最近更新 更多