How can I unzip a specific folder?

六眼飞鱼酱① 提交于 2019-12-05 13:11:40

问题


How can I unzip a specific folder with Ant?

Specifically, I have downloaded apache-tomcat-6.0.29.zip which contains the folder "apache-tomcat-6.0.29". I want Ant to unzip everything under "apache-tomcat-6.0.29" but not include "apache-tomcat-6.0.29" in the top of hierarchy.

I've tried a bunch of things, but I can't seem to get it to work.

Here's my latest attempt:

<unzip dest="${release.dir}/image/tomcat" src="${tomcat.zip}">
    <patternset>
        <include name="apache-tomcat-6.0.29/*"/>
    </patternset>
</unzip>

Any ideas?


回答1:


You can use a mapper within the unzip task to change the paths written.

<unzip dest="${release.dir}/image/tomcat" src="${tomcat.zip}">
    <patternset>
        <include name="apache-tomcat-6.0.29/*"/>
    </patternset>
    <mapper>
        <globmapper from="apache-tomcat-6.0.29/*" to="*"/>
    </mapper>
</unzip>



回答2:


The following works as long that there is a single directory in the tomcat archive.

<untar src="${release.dir}" dest="${tomcat.tar.gz}" compression="gzip">
  <cutdirsmapper dirs="1" />
</untar>



回答3:


<unzip dest="${release.dir}/image/tomcat" src="${tomcat.zip}">
    <patternset>
        <!-- add another star -->
        <include name="apache-tomcat-6.0.29/**"/>
    </patternset>
</unzip>


来源:https://stackoverflow.com/questions/3998090/how-can-i-unzip-a-specific-folder

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