使用ANT从嵌套的zip文件中解压缩特定的zip文件

问题描述

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

我确实尝试了以下代码段,但还没有发现好运-

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

请告知如何实现。

解决方法

来自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}"/>
,

PatternSets 用于选择要从存档中提取的文件。如果未使用patternset,则将提取所有文件。

文件集 可用于选择存档文件以对其执行取消存档。

尝试一下:

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