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

匆匆过客 提交于 2019-12-07 09:41:12

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/22759314/how-do-i-flatten-the-top-level-folder-of-a-zip-file-with-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!