Delete folders except one

in the src folder I have the following folders: daos, business and model, I want to delete with the ant script all the folders except "model", so I tried:

<delete includeemptydirs="true"> <fileset dir="${basedir}/src"> <include name="**/*"/> <exclude name="model/*"/> </fileset> </delete> 

All folders are deleted expet "model", which is empty! all its files are deleted!

+6
source share
2 answers

Try instead

 <delete includeemptydirs="true"> <fileset dir="${basedir}/src"> <include name="**/*"/> <exclude name="**/model/**"/> </fileset> </delete> 
+8
source

To the search engines of the future:

What worked for me:

 <fileset dir="target"> <include name="*/"/> <exclude name="big_and_complex_dir/"/> </fileset> 

This removed everything (all files and directories) below target/ except target/big_and_complex_dir .

My goal was to avoid unnecessary directory big_and_complex_dir , which took a lot of time in the case of " big_and_complex_dir ".

It seems that the interpretation of the ant file set has non-trivial, non-intuitive behavior, we need to close the include / exclude path with / if we also intend to perform the operations of the recursive subdirectory.

+6
source

All Articles