英文:
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:
<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
得分: -1
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>
英文:
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:
<unzip src="test.zip" dest="test_dir">
<patternset>
<include name="A.zip"/>
</patternset>
<fileset dir="test_dir">
<include name="A.zip"/>
</fileset>
</unzip>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论