【问题标题】:Unzip specific zip file from nested zip file using ANT使用 ANT 从嵌套的 zip 文件中解压缩特定的 zip 文件
【发布时间】:2020-11-30 13:51:07
【问题描述】:

我有一个 zip 文件。 “test.zip”,其中包含另外 2 个 zip 文件 - A.zip 和 B.zip。我只想提取 A.zip 的内容,而 B.zip 保持不变。

我确实尝试了下面的代码 sn-p,但还没有找到运气-

<unzip src="test.zip" dest="test_dir">
            <fileset dir="test_dir">
                <include name="A.zip"/>
                <exclude name="B.zip"/>
            </fileset>
        </unzip>

请告知如何实现。

【问题讨论】:

    标签: java build ant zip


    【解决方案1】:

    来自the unzip task’s documentation

    Unjar/Unwar/Unzip 仅支持基于文件系统的资源集合,包括文件集、文件列表、路径和文件。

    这意味着您必须在文件系统的某处拥有 A.zip 的物理副本。

    所以,除了分两步做之外,真的别无选择:

    <tempfile property="a" suffix=".zip"/>
    <copy tofile="${a}">
        <zipentry zipfile="test.zip" name="A.zip"/>
    </copy>
    
    <unzip src="${a}" dest="test_dir"/>
    <delete file="${a}"/>
    

    【讨论】:

      【解决方案2】:

      PatternSets 用于选择要从存档中提取的文件。如果不使用模式集,则提取所有文件。

      FileSets 可用于选择存档文件以执行取消存档。

      试试这个:

      <unzip src="test.zip" dest="test_dir">
                  <patternset>
                      <include name="A.zip"/>
                  </patternset>
                  <fileset dir="test_dir">
                      <include name="A.zip"/>
                  </fileset>
              </unzip>
      

      【讨论】:

      • 嵌套文件集不会在 inside test.zip 中查看。它将在 test_dir 中查找现有的 A.zip。
      • @fatalcoder524 - 我试过这个,但虽然“A.zip”确实从“test.zip”中提取出来,但“A.zip”本身并没有被提取出来。
      • @VGR - 是的,这似乎正在发生。在同一步骤中提取“A.zip”本身的任何方法?
      猜你喜欢
      • 2017-05-24
      • 2021-05-29
      • 1970-01-01
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多