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


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:


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?

Best Solution

It's not dynamic, but using the fullpath attribute allows you to define the path struture of the zip file. See ant documentation:

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

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="*"/>
<zip destfile="" basedir="DirToBeZipped"/>