How to smooth the top level folder of a zip file using ant?

Many zip files have a root folder, how do I unzip a zip file and get rid of the root folder?

I know that there are globmapper:

<unzip dest="${dest.path}">
    <fileset dir="${source.path}">
        <include name="**/zipfile*.*.zip" />
    </fileset>
    <mapper>
        <globmapper from="rootFolder/*" to="*" />
    </mapper>
</unzip>

But what if I do not know the name of the root folder? Wildcards do not work, for example.

<globmapper from="root*Folder/*" to="*" />

Is there a way to use wildcards or mapper / function that suit without a root folder?

+4
source share
1 answer

This is actually a separate calculator specially created for this, called cutdirsmapper. Try:

<unzip dest="${dest.path}">
    <fileset dir="${source.path}">
        <include name="**/zipfile*.*.zip" />
    </fileset>
    <cutdirsmapper dirs="1" />
</unzip>
+10
source

Source: https://habr.com/ru/post/1534230/


All Articles