从嵌套的ZIP文件中使用ANT解压特定的ZIP文件。

huangapple go评论82阅读模式
英文:

Unzip specific zip file from nested zip file using ANT

问题

I have a zip file ex. 'test.zip' that contains 2 more zip files within it - A.zip and B.zip. I want to only extract contents of A.zip and leave B.zip untouched.

我有一个名为 'test.zip' 的压缩文件,其中包含2个更多的压缩文件 - A.zip 和 B.zip。我只想解压缩 A.zip 的内容,不要碰 B.zip。

I did try out the below code snippet, but found no luck yet -

我尝试了下面的代码片段,但尚未成功 -






Please advise how this could be achieved.

请指导如何实现这个目标。

英文:

I have a zip file ex. 'test.zip' that contains 2 more zip files within it - A.zip and B.zip. I want to only extract contents of A.zip and leave B.zip untouched.

I did try out the below code snippet, but found no luck yet -

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

Please advise how this could be achieved.

答案1

得分: 0

解压缩任务的文档中:

"Unjar/Unwar/Unzip"仅支持基于文件系统的资源集合,包括fileset、filelist、path和files。

这意味着您必须在文件系统的某个地方有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}"/>
英文:

From the unzip task’s documentation:

>Only file system based resource collections are supported by Unjar/Unwar/Unzip, this includes fileset, filelist, path, and files.

This means you have to have a physical copy of A.zip somewhere on the file system.

So, there really is no choice other than doing it in two steps:

&lt;tempfile property=&quot;a&quot; suffix=&quot;.zip&quot;/&gt;
&lt;copy tofile=&quot;${a}&quot;&gt;
    &lt;zipentry zipfile=&quot;test.zip&quot; name=&quot;A.zip&quot;/&gt;
&lt;/copy&gt;

&lt;unzip src=&quot;${a}&quot; dest=&quot;test_dir&quot;/&gt;
&lt;delete file=&quot;${a}&quot;/&gt;

答案2

得分: -1

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

FileSets 可以用于选择要执行解档操作的已存档文件。

试试这个:

&lt;unzip src=&quot;test.zip&quot; dest=&quot;test_dir&quot;&gt;
            &lt;patternset&gt;
                &lt;include name=&quot;A.zip&quot;/&gt;
            &lt;/patternset&gt;
            &lt;fileset dir=&quot;test_dir&quot;&gt;
                &lt;include name=&quot;A.zip&quot;/&gt;
            &lt;/fileset&gt;
        &lt;/unzip&gt;
英文:

PatternSets are used to select files to extract from the archive. If no patternset is used, all files are extracted.

FileSets may be used used to select archived files to perform unarchival upon.

Try this:

&lt;unzip src=&quot;test.zip&quot; dest=&quot;test_dir&quot;&gt;
            &lt;patternset&gt;
                &lt;include name=&quot;A.zip&quot;/&gt;
            &lt;/patternset&gt;
            &lt;fileset dir=&quot;test_dir&quot;&gt;
                &lt;include name=&quot;A.zip&quot;/&gt;
            &lt;/fileset&gt;
        &lt;/unzip&gt;

huangapple
  • 本文由 发表于 2020年8月11日 06:41:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63348992.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定