Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant: Zip the contents of a directory, without the top-level directory itself

Tags:

zip

ant

How can I use Ant to create zip containing all the files and nested directories inside some root directory, but exclude the top-level directory itself from the zip.

For example, say I have this file structure:

/foo
    splat.js
    /bar
        wheee.css

I want the zip to contain splat, and wheee inside /bar, but I don't want all that to be contained inside a 'foo' directory. In other words, unzipping this into /honk should not create a foo directory; splat and bar should end up at the root of /honk.

I'm currently using this (extraneous details removed):

<zip destfile="${zipfile}" basedir="" includes="${distRoot}/**/*.*" />

What kind of fileset select can replace that 'includes' spec to achieve this?

like image 644
enigment Avatar asked Nov 04 '22 06:11

enigment


1 Answers

It's not dynamic, but using the fullpath attribute allows you to define the path struture of the zip file. See ant documentation: http://ant.apache.org/manual/Types/zipfileset.html

<zip destfile="YourZipName.zip">
    <zipfileset fullpath="splat.js" dir="foo" includes="splat.js"/>
    <zipfileset fullpath="bar/wheee.css" dir="foo/bar" includes="wheee.css"/>
</zip>

This may get you want you want dynamically. It should pull in everything in the foo dir then zip it up. It's just a few extra steps.

<mkdir dir="DirToBeZipped"/>
<copy todir="DirToBeZipped">
    <fileset dir="foo" includes="*"/>
</copy>
<zip destfile="YourZipName.zip" basedir="DirToBeZipped"/>
like image 162
Makeen A. Sabree Avatar answered Nov 11 '22 12:11

Makeen A. Sabree