Recursively delete all files of the same type using Ant

In ant build script, how can I delete all *.java files in one directory and in its subdirectory?

+4
source share
3 answers

It is unclear how deep in the directory tree you want to delete .java files. I will provide ways to do both.

Complete recursive deletion

Recursively deletes all .java files anywhere in the provided destination directory.

 <delete> <fileset dir="${basedir}/path/to/target/directory" includes="**/*.java"/> </delete> 

Only in the target directory and its immediate child directories

Deletes .java files in the specified target directory and in any directories that are direct children of the target directory, but no more.

 <delete> <fileset dir="${basedir}/path/to/target/directory" includes="*.java,*/*.java"/> </delete> 

See the documentation for the uninstall task for additional options.

Be careful . If you put the wrong directory in your target directory, you can delete those things that you do not want. Consider creating paths to the target directory relative to the assembly file or ${basedir} .

+15
source
 <delete> <fileset dir="." includes="**/*.java"/> </delete> 

The above delete task deletes all files with the .java extension from the current directory and any subdirectories.

+2
source
 <delete> <filename name="**/*.java"/> </delete> 

http://ant.apache.org/manual/Types/fileset.html

-1
source

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


All Articles