简体   繁体   中英

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.

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.

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}"/>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM