Home » Apache Ant Delete Task

Apache Ant Delete Task

by Online Tutorials Library

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

Attribute Description Required
file The file to be deleted Resource (file,directory)
dir The directory to delete.
verbose Whether to show the name of each deleted file. No
quiet If resource is not exist, it does not display any message. No
failonerror It displays error on fail to delete the resource. No
includeemptydirs Delete empty directory too. No
includes List of files to be deleted. No
includesfile Includes file to be deleted. No
excludes Exclude file to delete. No
excludesfile Exclude to delete file. No
defaultexcludes Set default exclude. No
deleteonexit Delete on exit. No
removeNotFollowedSymlinks Whether symbolic links (not the files/directories they link to) should be removed. No
performGCOnFailedDelete If 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.

You may also like