如何使用 ant 单独压缩多个文件夹? [英] How can I zip multiple folders individually with ant?

查看:57
本文介绍了如何使用 ant 单独压缩多个文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个文件夹有多个子文件夹(例如foo、bar、baz),我如何使用ant将它们分别压缩成foo.zip、bar.zip和baz.zip,而不是一一压缩?

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".

推荐答案

您不想使用 ant-contrib.ant-contrib 很糟糕,每次使用它时,都会产生技术债务.使用 ant 时要记住的第一件事:让 ant 成为 ant.蚂蚁就是它.它是声明性的.蚂蚁的初衷 是简单的属性声明,并且大部分工作都是在 java 中完成的(在那里你有一个带有调试器和测试框架的真正 IDE).如蚂蚁风格的元素 - 让蚂蚁成为蚂蚁"中所述.如果你必须使用 ant-contrib,你应该制作你自己的 ant 任务.如果你不能这样做,不要使用蚂蚁.ant-contrib 采取了最糟糕的 ant ant 使情况变得更糟,你很快就会发现事情无法维护.够唠叨了.

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.

你甚至不需要为此做一项任务,这应该可以工作......它需要/tmp 中的所有 dir 并将其压缩.应该可以让您完成大部分任务.

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>

这篇关于如何使用 ant 单独压缩多个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆