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

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

For example, let's 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 it all to be in the 'foo' directory. In other words, unzipping this file in / honk should not create the foo directory; splat and bar should end in root / honk.

I am currently using this (extraneous details removed):

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

What type of file set can replace the "includes" value for this?

+4
source share
1 answer

This is not dynamic, but using the fullpath attribute you can define the strread path for the zip file. See the 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 can make you want you to want dynamically. He has to pull everything in foo dir and then fasten it. These are just a few extra steps.

 <mkdir dir="DirToBeZipped"/> <copy todir="DirToBeZipped"> <fileset dir="foo" includes="*"/> </copy> <zip destfile="YourZipName.zip" basedir="DirToBeZipped"/> 
+1
source

Source: https://habr.com/ru/post/1394453/


All Articles