Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I zip multiple folders individually with ant?

Tags:

ant

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

like image 302
aditsu quit because SE is EVIL Avatar asked Jan 17 '26 09:01

aditsu quit because SE is EVIL


1 Answers

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>
like image 114
thekbb Avatar answered Jan 21 '26 08:01

thekbb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!