In an ant build script, how can I delete all *.java
files in one directory and its subdirectory?
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}
.
<delete>
<fileset dir="." includes="**/*.java"/>
</delete>
The above delete task deletes all files with the extension .java from the current directory and any subdirectories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With