Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I flatten the top level folder of a zip file with ant?

A lot of zip files have a root folder, how do I unpack the zip file and get rid of the root folder?

I know there is the 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 don't know the name of the root folder? Wildcards are not working e.g.

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

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

like image 472
flavio.donze Avatar asked Mar 31 '14 10:03

flavio.donze


1 Answers

There's actually a separate mapper specifically made for this called cutdirsmapper. Give this a try:

<unzip dest="${dest.path}">
    <fileset dir="${source.path}">
        <include name="**/zipfile*.*.zip" />
    </fileset>
    <cutdirsmapper dirs="1" />
</unzip>
like image 85
CAustin Avatar answered Jan 11 '23 23:01

CAustin