Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively deleting all files of one type using Ant

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

like image 868
user534009 Avatar asked Mar 16 '11 16:03

user534009


2 Answers

It's slightly unclear how deep in the directory tree you would like to delete the .java files. I'll provide ways to do both.

Full recursive delete

Recursively deletes all .java files anywhere under the provided target directory.

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

Only within the target directory and its immediate child directories

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

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

For additional options, have a look at the documentation for the delete task.

Be careful - If you put the wrong directory in for your target directory, you might delete things you don't want to. Consider making the paths to your target dir relative to the build file, or to ${basedir}.

like image 196
Rob Hruska Avatar answered Sep 30 '22 07:09

Rob Hruska


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

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

like image 32
Piyush Mattoo Avatar answered Sep 30 '22 06:09

Piyush Mattoo