Delete files and directories recursively.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.io |
Category: | I/O tasks |
Since: | 0.5 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory |
See also: | DeleteTF RecursiveActionTF |
Description:
Delete files and directories recursively from one or more directory hierarchies.
Required properties
Properties
deleteRoot | top |
Should the root directories (the directories added to the sources property) also be deleted? The default behavior is to only delete their contents.
- Setter method:
setDeleteRoot(boolean dr)
parameters:dr
– Should the root directory/directories be deleted?- Default value:
false
(The root directory is not deleted.)
logFooter | top |
The message that is logged to info
level
after the task has been successfully run.
- Setter method:
setLogFooter(String s)
parameters:s
– The footer message.- Default value:
- Empty (no footer message is logged.)
- See also:
- logHeader
logHeader | top |
The message that is logged to info
level
before the task is run.
- Setter method:
setLogHeader(String s)
parameters:s
– The header message.- Default value:
- A task class specific message.
- See also:
- logFooter
preserveAttributes | top |
Should attributes of the source entities, such as their latest modification times, be copied to the target entities?
- Setter method:
setPreserveAttributes(boolean b)
parameters:b
– Should attributes be preserved?- Default value:
false
(attributes are not preserved)
reportLevel | top |
This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.
- Setter method:
setReportLevel(Level l)
Set the report levelparameters:l
– The new report level.
sources (required) | top |
A collection of directories to delete recursively.
There are two ways that EntityFilter:s can be used to exclude files or directories from being deleted:
- Using a DirectoryView as source: This task will only delete files and directories that match the view's filter, and it will only delete directories without child entities. Furthermore, it will only recurse down into child directories that match the filter.
- Using a DirectoryAndFilter as source: This task will only delete files and directories that match the view's filter, and it will only delete directories without child entities. It will however recurse down into all child directories of a processed directory.
See the examples below
- Setter method:
addSource(Object o)
Add one or several sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsDirectoryStrategy
.- Setter method:
addSources(Object o)
Add one or several sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsDirectoryStrategy
.- Setter method:
clearSources()
Discard all sources.- Setter method:
setSource(Object o)
Set one or several sources and discard previously set sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsDirectoryStrategy
.- Setter method:
setSources(Object o)
Set one or several sources and discard previously set sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsDirectoryStrategy
.
traceLogging | top |
If trace logging is enabled for a task, it reports its configuration before it is run.
Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).
- Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.parameters:b
– Enable trace logging?
Examples
Example 1
Delete all files and subdirectories of d1
.
d1
itself is not deleted.
JavaScript
Example 2
Delete all .svn
directories in
d1
's directory hierarchy.
JavaScript
Example 3
This is an alternative way of deleting the
.svn
directories compared to the previous example. Instead of using
the SuperParentOrFilter with the TreeDeleteTF, it
uses the RecursiveActionTF
to define a new TreeDeleteTF task for each .svn
directory found.
JavaScript
Example 4
This is yet another way of deleting the .svn
directories (see the
two previous examples). This time, a FilteringIterator is
used.
Groovy
JavaScript
JRuby
Jython
* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.