Apache Ant Delete Task

This task is used to delete a single file, directory or subdirectories. We can also delete set of files by specifying set of files. It does not remove empty directory by default, we need to use includeEmptyDirs attribute to remove that directory.

It has various attributes that are tabled below.

Apache Ant Delete Task Attributes

AttributeDescriptionRequired
fileThe file to be deletedResource (file,directory)
dirThe directory to delete.
verboseWhether to show the name of each deleted file.No
quietIf resource is not exist, it does not display any message.No
failonerrorIt displays error on fail to delete the resource.No
includeemptydirsDelete empty directory too.No
includesList of files to be deleted.No
includesfileIncludes file to be deleted.No
excludesExclude file to delete.No
excludesfileExclude to delete file.No
defaultexcludesSet default exclude.No
deleteonexitDelete on exit.No
removeNotFollowedSymlinksWhether symbolic links (not the files/directories they link to) should be removed.No
performGCOnFailedDeleteIf Ant fails to delete a file or directory it will retry the operation once.No

Apache Ant Delete Example

Lets see an example to understand the functioning of delete task.

Delete a File

Delete a Directory

Delete all the .java files from the current directory and subdirectories.

Delete all the files and subdirectories of build, even build itself.





Latest Courses