How can I zip multiple folders individually with ant?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 14:04:16

问题


If I have a folder with multiple subfolders (e.g. foo, bar, baz), how can I use ant to zip them individually into foo.zip, bar.zip and baz.zip, without doing them one by one?

Ideally there should also be a way to specify which files/subfolders to zip rather than "every single one".


回答1:


You don't want to use ant-contrib. ant-contrib sucks, every time you use it, you're incurring technical debt. The number one thing to keep in mind when using ant: let ant be ant. ant is what it is. it's declarative. The original intent of ant was simple declarations of properties and with the meat of the work being done in java (where you had a real IDE with a debugger and test frameworks). As noted in elements of ant style - "Let ant be ant". If you have to use ant-contrib, you should make your own ant task. If you can't do that, don't use ant. ant-contrib takes the worst of ant ant makes it worse, you'll soon find things unmaintainable. Enough ranting.

You don't even need to make a task for this one, this should work... it takes everything dir in /tmp and zips it up. should get you most of the way there.

    <mapper id="zip" type="glob"
    from="*"
    to="*.zip"/>

<target name="zip-craziness">
    <apply executable="zip">
        <targetfile/>
        <srcfile/>
        <dirset dir="/tmp" />
         <mapper refid="zip"/>
    </apply>
</target>



回答2:


I used for-each from ant contrib for this kind of thing. You may able to improve on this question : Ant: How to execute a command for each file in directory?



来源:https://stackoverflow.com/questions/6300704/how-can-i-zip-multiple-folders-individually-with-ant

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