Delete (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.taskdefs, class: Delete

# Class Delete

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.MatchingTask
org.apache.tools.ant.taskdefs.Delete

All Implemented Interfaces:
  `Cloneable, SelectorContainer`

public class Delete extends MatchingTask
Deletes a file or directory, or set of files defined by a fileset. The original delete task would delete a file, or a set of files using the include/exclude syntax. The deltree task would delete a directory tree. This task combines the functionality of these two originally distinct tasks.

Currently Delete extends MatchingTask. This is intended only to provide backwards compatibility for a release. The future position is to use nested filesets exclusively.

Since:
  Ant 1.2

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected File`
  `dir`
  `protected File`
  `file`
  `protected Vector<FileSet>`
  `filesets`
  `protected boolean`
  `includeEmpty`
  `protected File`
  `link`
  `protected boolean`
  `usedMatchingTask`

  ### Fields inherited from class MatchingTask

  `fileset`
  Modifier and Type
  Field
  Description
  `protected FileSet`
  `fileset`

  ### Fields inherited from class Task

  `target, taskName, taskType, wrapper`
  Modifier and Type
  Field
  Description
  `protected Target`
  `target`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskName`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskType`
  Deprecated.
  since 1.6.x.
  `protected RuntimeConfigurable`
  `wrapper`
  Deprecated.
  since 1.6.x.

  ### Fields inherited from class ProjectComponent

  `description, location, project`
  Modifier and Type
  Field
  Description
  `protected String`
  `description`
  Deprecated.
  since 1.6.x.
  `protected Location`
  `location`
  Deprecated.
  since 1.6.x.
  `protected Project`
  `project`
  Deprecated.
  since 1.6.x.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Delete()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(ResourceCollection rc)`
  Add an arbitrary ResourceCollection to be deleted.
  `void`
  `add(FileSelector selector)`
  add an arbitrary selector
  `void`
  `addAnd(AndSelector selector)`
  add an "And" selector entry on the selector list
  `void`
  `addContains(ContainsSelector selector)`
  add a contains selector entry on the selector list
  `void`
  `addContainsRegexp(ContainsRegexpSelector selector)`
  add a regular expression selector entry on the selector list
  `void`
  `addCustom(ExtendSelector selector)`
  add an extended selector entry on the selector list
  `void`
  `addDate(DateSelector selector)`
  add a selector date entry on the selector list
  `void`
  `addDepend(DependSelector selector)`
  add a depends selector entry on the selector list
  `void`
  `addDepth(DepthSelector selector)`
  add a depth selector entry on the selector list
  `void`
  `addFilename(FilenameSelector selector)`
  add a selector filename entry on the selector list
  `void`
  `addFileset(FileSet set)`
  Adds a set of files to be deleted.
  `void`
  `addMajority(MajoritySelector selector)`
  add a majority selector entry on the selector list
  `void`
  `addModified(ModifiedSelector selector)`
  add the modified selector
  `void`
  `addNone(NoneSelector selector)`
  add a "None" selector entry on the selector list
  `void`
  `addNot(NotSelector selector)`
  add a "Not" selector entry on the selector list
  `void`
  `addOr(OrSelector selector)`
  add an "Or" selector entry on the selector list
  `void`
  `addPresent(PresentSelector selector)`
  add a present selector entry on the selector list
  `void`
  `addSelector(SelectSelector selector)`
  add a "Select" selector entry on the selector list
  `void`
  `addSize(SizeSelector selector)`
  add a selector size entry on the selector list
  `PatternSet.NameEntry`
  `createExclude()`
  add a name entry on the exclude list
  `PatternSet.NameEntry`
  `createExcludesFile()`
  add a name entry on the include files list
  `PatternSet.NameEntry`
  `createInclude()`
  add a name entry on the include list
  `PatternSet.NameEntry`
  `createIncludesFile()`
  add a name entry on the include files list
  `PatternSet`
  `createPatternSet()`
  add a set of patterns
  `void`
  `execute()`
  Delete the file(s).
  `protected void`
  `removeDir(File d)`
  Delete a directory
  `protected void`
  `removeFiles(File d, String[] files, String[] dirs)`
  remove an array of files in a directory, and a list of subdirectories which will only be deleted if 'includeEmpty' is true
  `void`
  `setCaseSensitive(boolean isCaseSensitive)`
  Sets case sensitivity of the file system
  `void`
  `setDefaultexcludes(boolean useDefaultExcludes)`
  Sets whether default exclusions should be used or not.
  `void`
  `setDeleteOnExit(boolean deleteOnExit)`
  If true, on failure to delete, note the error and set the deleteonexit flag, and continue
  `void`
  `setDir(File dir)`
  Set the directory from which files are to be deleted
  `void`
  `setExcludes(String excludes)`
  Sets the set of exclude patterns.
  `void`
  `setExcludesfile(File excludesfile)`
  Sets the name of the file containing the includes patterns.
  `void`
  `setFailOnError(boolean failonerror)`
  If false, note errors but continue.
  `void`
  `setFile(File file)`
  Set the name of a single file to be removed.
  `void`
  `setFollowSymlinks(boolean followSymlinks)`
  Sets whether or not symbolic links or Windows junctions should be followed.
  `void`
  `setIncludeEmptyDirs(boolean includeEmpty)`
  If true, delete empty directories.
  `void`
  `setIncludes(String includes)`
  Sets the set of include patterns.
  `void`
  `setIncludesfile(File includesfile)`
  Sets the name of the file containing the includes patterns.
  `void`
  `setLink(File link)`
  Set the name of a single symbolic link or windows junction to be removed.
  `void`
  `setPerformGcOnFailedDelete(boolean b)`
  Whether to perform a garbage collection before retrying a failed delete.
  `void`
  `setQuiet(boolean quiet)`
  If true and the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.
  `void`
  `setRemoveNotFollowedSymlinks(boolean b)`
  Sets whether the symbolic links or Windows junctions that have not been followed shall be removed (the links, not the locations they point at).
  `void`
  `setVerbose(boolean verbose)`
  If true, list all names of deleted files.

  ### Methods inherited from class MatchingTask

  `addDifferent, addType, appendSelector, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setProject, XsetIgnore, XsetItems`
  Modifier and Type
  Method
  Description
  `void`
  `addDifferent(DifferentSelector selector)`
  add a type selector entry on the type list
  `void`
  `addType(TypeSelector selector)`
  add a type selector entry on the type list
  `void`
  `appendSelector(FileSelector selector)`
  Add a new selector into this container.
  `protected DirectoryScanner`
  `getDirectoryScanner(File baseDir)`
  Returns the directory scanner needed to access the files to process.
  `protected final FileSet`
  `getImplicitFileSet()`
  Accessor for the implicit fileset.
  `FileSelector[]`
  `getSelectors(Project p)`
  Returns the set of selectors as an array.
  `boolean`
  `hasSelectors()`
  Indicates whether there are any selectors here.
  `int`
  `selectorCount()`
  Gives the count of the number of selectors in this container
  `Enumeration<FileSelector>`
  `selectorElements()`
  Returns an enumerator for accessing the set of selectors.
  `void`
  `setProject(Project project)`
  Sets the project object of this component.
  `void`
  `XsetIgnore(String ignoreString)`
  List of filenames and directory names to not include.
  `void`
  `XsetItems(String itemString)`
  Set this to be the items in the base directory that you want to be included.

  ### Methods inherited from class Task

  `bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType`
  Modifier and Type
  Method
  Description
  `final void`
  `bindToOwner(Task owner)`
  Bind a task to another; use this when configuring a newly created task to do work on behalf of another.
  `Target`
  `getOwningTarget()`
  Returns the container target of this task.
  `RuntimeConfigurable`
  `getRuntimeConfigurableWrapper()`
  Returns the wrapper used for runtime configuration.
  `String`
  `getTaskName()`
  Returns the name to use in logging messages.
  `String`
  `getTaskType()`
  Return the type of task.
  `protected RuntimeConfigurable`
  `getWrapper()`
  Return the runtime configurable structure for this task.
  `protected void`
  `handleErrorFlush(String output)`
  Handles an error line by logging it with the WARN priority.
  `protected void`
  `handleErrorOutput(String output)`
  Handles an error output by logging it with the WARN priority.
  `protected void`
  `handleFlush(String output)`
  Handles output by logging it with the INFO priority.
  `protected int`
  `handleInput(byte[] buffer, int offset, int length)`
  Handle an input request by this task.
  `protected void`
  `handleOutput(String output)`
  Handles output by logging it with the INFO priority.
  `void`
  `init()`
  Called by the project to let the task initialize properly.
  `protected final boolean`
  `isInvalid()`
  Has this task been marked invalid?
  `void`
  `log(String msg)`
  Logs a message with the default (INFO) priority.
  `void`
  `log(String msg, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(String msg, Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `maybeConfigure()`
  Configures this task - if it hasn't been done already.
  `final void`
  `perform()`
  Performs this task if it's still valid, or gets a replacement version and performs that otherwise.
  `void`
  `reconfigure()`
  Force the task to be reconfigured from its RuntimeConfigurable.
  `void`
  `setOwningTarget(Target target)`
  Sets the target container of this task.
  `void`
  `setRuntimeConfigurableWrapper(RuntimeConfigurable wrapper)`
  Sets the wrapper to be used for runtime configuration.
  `void`
  `setTaskName(String name)`
  Sets the name to use in logging messages.
  `void`
  `setTaskType(String type)`
  Sets the name with which the task has been invoked.

  ### Methods inherited from class ProjectComponent

  `clone, getDescription, getLocation, getProject, setDescription, setLocation`
  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `String`
  `getDescription()`
  Returns the description of the current action.
  `Location`
  `getLocation()`
  Returns the file/location where this task was defined.
  `Project`
  `getProject()`
  Returns the project to which this component belongs.
  `void`
  `setDescription(String desc)`
  Sets a description of the current action.
  `void`
  `setLocation(Location location)`
  Sets the file/location where this task was defined.

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### file

    protected File file

  - ### link

    protected File link

  - ### dir

    protected File dir

  - ### filesets

    protected Vector<FileSet> filesets

  - ### usedMatchingTask

    protected boolean usedMatchingTask

  - ### includeEmpty

    protected boolean includeEmpty

- ## Constructor Details

  - ### Delete

    public Delete()

- ## Method Details

  - ### setFile

    public void setFile(File file)
    Set the name of a single file to be removed.
    Parameters:
      `file` - the file to be deleted

  - ### setLink

    public void setLink(File link)
    Set the name of a single symbolic link or windows junction to be removed.
    Parameters:
      `file` - the link to be deleted
    Since:
      Ant 1.10.16

  - ### setDir

    public void setDir(File dir)
    Set the directory from which files are to be deleted
    Parameters:
      `dir` - the directory path.

  - ### setVerbose

    public void setVerbose(boolean verbose)
    If true, list all names of deleted files.
    Parameters:
      `verbose` - "true" or "on"

  - ### setQuiet

    public void setQuiet(boolean quiet)
    If true and the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. This means that if a file or directory cannot be deleted, then no error is reported. This setting emulates the -f option to the Unix "rm" command. Default is false meaning things are "noisy"
    Parameters:
      `quiet` - "true" or "on"

  - ### setFailOnError

    public void setFailOnError(boolean failonerror)
    If false, note errors but continue.
    Parameters:
      `failonerror` - true or false

  - ### setDeleteOnExit

    public void setDeleteOnExit(boolean deleteOnExit)
    If true, on failure to delete, note the error and set the deleteonexit flag, and continue
    Parameters:
      `deleteOnExit` - true or false

  - ### setIncludeEmptyDirs

    public void setIncludeEmptyDirs(boolean includeEmpty)
    If true, delete empty directories.
    Parameters:
      `includeEmpty` - if true delete empty directories (only for filesets). Default is false.

  - ### setPerformGcOnFailedDelete

    public void setPerformGcOnFailedDelete(boolean b)
    Whether to perform a garbage collection before retrying a failed delete.

    This may be required on Windows (where it is set to true by default) but also on other operating systems, for example when deleting directories from an NFS share.

    Parameters:
      `b` - boolean
    Since:
      Ant 1.8.3

  - ### addFileset

    public void addFileset(FileSet set)
    Adds a set of files to be deleted.
    Parameters:
      `set` - the set of files to be deleted

  - ### add

    public void add(ResourceCollection rc)
    Add an arbitrary ResourceCollection to be deleted.
    Parameters:
      `rc` - the filesystem-only ResourceCollection.

  - ### createInclude

    public PatternSet.NameEntry createInclude()
    add a name entry on the include list
    Overrides:
      `createInclude` in class `MatchingTask`
    Returns:
      a NameEntry object to be configured

  - ### createIncludesFile

    public PatternSet.NameEntry createIncludesFile()
    add a name entry on the include files list
    Overrides:
      `createIncludesFile` in class `MatchingTask`
    Returns:
      a PatternFileNameEntry object to be configured

  - ### createExclude

    public PatternSet.NameEntry createExclude()
    add a name entry on the exclude list
    Overrides:
      `createExclude` in class `MatchingTask`
    Returns:
      a NameEntry object to be configured

  - ### createExcludesFile

    public PatternSet.NameEntry createExcludesFile()
    add a name entry on the include files list
    Overrides:
      `createExcludesFile` in class `MatchingTask`
    Returns:
      a PatternFileNameEntry object to be configured

  - ### createPatternSet

    public PatternSet createPatternSet()
    add a set of patterns
    Overrides:
      `createPatternSet` in class `MatchingTask`
    Returns:
      PatternSet object to be configured

  - ### setIncludes

    public void setIncludes(String includes)
    Sets the set of include patterns. Patterns may be separated by a comma or a space.
    Overrides:
      `setIncludes` in class `MatchingTask`
    Parameters:
      `includes` - the string containing the include patterns

  - ### setExcludes

    public void setExcludes(String excludes)
    Sets the set of exclude patterns. Patterns may be separated by a comma or a space.
    Overrides:
      `setExcludes` in class `MatchingTask`
    Parameters:
      `excludes` - the string containing the exclude patterns

  - ### setDefaultexcludes

    public void setDefaultexcludes(boolean useDefaultExcludes)
    Sets whether default exclusions should be used or not.
    Overrides:
      `setDefaultexcludes` in class `MatchingTask`
    Parameters:
      `useDefaultExcludes` - "true"|"on"|"yes" when default exclusions should be used, "false"|"off"|"no" when they shouldn't be used.

  - ### setIncludesfile

    public void setIncludesfile(File includesfile)
    Sets the name of the file containing the includes patterns.
    Overrides:
      `setIncludesfile` in class `MatchingTask`
    Parameters:
      `includesfile` - A string containing the filename to fetch the include patterns from.

  - ### setExcludesfile

    public void setExcludesfile(File excludesfile)
    Sets the name of the file containing the includes patterns.
    Overrides:
      `setExcludesfile` in class `MatchingTask`
    Parameters:
      `excludesfile` - A string containing the filename to fetch the include patterns from.

  - ### setCaseSensitive

    public void setCaseSensitive(boolean isCaseSensitive)
    Sets case sensitivity of the file system
    Overrides:
      `setCaseSensitive` in class `MatchingTask`
    Parameters:
      `isCaseSensitive` - "true"|"on"|"yes" if file system is case sensitive, "false"|"off"|"no" when not.

  - ### setFollowSymlinks

    public void setFollowSymlinks(boolean followSymlinks)
    Sets whether or not symbolic links or Windows junctions should be followed.
    Overrides:
      `setFollowSymlinks` in class `MatchingTask`
    Parameters:
      `followSymlinks` - whether or not symbolic links or Windows junctions should be followed

  - ### setRemoveNotFollowedSymlinks

    public void setRemoveNotFollowedSymlinks(boolean b)
    Sets whether the symbolic links or Windows junctions that have not been followed shall be removed (the links, not the locations they point at).
    Parameters:
      `b` - boolean
    Since:
      Ant 1.8.0, support for junctions has been added with 1.10.16

  - ### addSelector

    public void addSelector(SelectSelector selector)
    add a "Select" selector entry on the selector list
    Specified by:
      `addSelector` in interface `SelectorContainer`
    Overrides:
      `addSelector` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addAnd

    public void addAnd(AndSelector selector)
    add an "And" selector entry on the selector list
    Specified by:
      `addAnd` in interface `SelectorContainer`
    Overrides:
      `addAnd` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addOr

    public void addOr(OrSelector selector)
    add an "Or" selector entry on the selector list
    Specified by:
      `addOr` in interface `SelectorContainer`
    Overrides:
      `addOr` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addNot

    public void addNot(NotSelector selector)
    add a "Not" selector entry on the selector list
    Specified by:
      `addNot` in interface `SelectorContainer`
    Overrides:
      `addNot` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addNone

    public void addNone(NoneSelector selector)
    add a "None" selector entry on the selector list
    Specified by:
      `addNone` in interface `SelectorContainer`
    Overrides:
      `addNone` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addMajority

    public void addMajority(MajoritySelector selector)
    add a majority selector entry on the selector list
    Specified by:
      `addMajority` in interface `SelectorContainer`
    Overrides:
      `addMajority` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addDate

    public void addDate(DateSelector selector)
    add a selector date entry on the selector list
    Specified by:
      `addDate` in interface `SelectorContainer`
    Overrides:
      `addDate` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addSize

    public void addSize(SizeSelector selector)
    add a selector size entry on the selector list
    Specified by:
      `addSize` in interface `SelectorContainer`
    Overrides:
      `addSize` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addFilename

    public void addFilename(FilenameSelector selector)
    add a selector filename entry on the selector list
    Specified by:
      `addFilename` in interface `SelectorContainer`
    Overrides:
      `addFilename` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addCustom

    public void addCustom(ExtendSelector selector)
    add an extended selector entry on the selector list
    Specified by:
      `addCustom` in interface `SelectorContainer`
    Overrides:
      `addCustom` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addContains

    public void addContains(ContainsSelector selector)
    add a contains selector entry on the selector list
    Specified by:
      `addContains` in interface `SelectorContainer`
    Overrides:
      `addContains` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addPresent

    public void addPresent(PresentSelector selector)
    add a present selector entry on the selector list
    Specified by:
      `addPresent` in interface `SelectorContainer`
    Overrides:
      `addPresent` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addDepth

    public void addDepth(DepthSelector selector)
    add a depth selector entry on the selector list
    Specified by:
      `addDepth` in interface `SelectorContainer`
    Overrides:
      `addDepth` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addDepend

    public void addDepend(DependSelector selector)
    add a depends selector entry on the selector list
    Specified by:
      `addDepend` in interface `SelectorContainer`
    Overrides:
      `addDepend` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addContainsRegexp

    public void addContainsRegexp(ContainsRegexpSelector selector)
    add a regular expression selector entry on the selector list
    Specified by:
      `addContainsRegexp` in interface `SelectorContainer`
    Overrides:
      `addContainsRegexp` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added

  - ### addModified

    public void addModified(ModifiedSelector selector)
    add the modified selector
    Specified by:
      `addModified` in interface `SelectorContainer`
    Overrides:
      `addModified` in class `MatchingTask`
    Parameters:
      `selector` - the selector to add
    Since:
      ant 1.6

  - ### add

    public void add(FileSelector selector)
    add an arbitrary selector
    Specified by:
      `add` in interface `SelectorContainer`
    Overrides:
      `add` in class `MatchingTask`
    Parameters:
      `selector` - the selector to be added
    Since:
      Ant 1.6

  - ### execute

    public void execute() throws BuildException
    Delete the file(s).
    Overrides:
      `execute` in class `Task`
    Throws:
      `BuildException` - if an error occurs

  - ### removeDir

    protected void removeDir(File d)
    Delete a directory
    Parameters:
      `d` - the directory to delete

  - ### removeFiles

    protected void removeFiles(File d, String[] files, String[] dirs)
    remove an array of files in a directory, and a list of subdirectories which will only be deleted if 'includeEmpty' is true
    Parameters:
      `d` - directory to work from
      `files` - array of files to delete; can be of zero length
      `dirs` - array of directories to delete; can of zero length