diff --git a/docs/index.html b/docs/index.html index 8ad1ed63e..426e4c3cb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2075,7 +2075,8 @@ repository pointed to by the cvsRoot attribute, and stores the files in "${

Description

Deletes either a single file, all files in a specified directory and its sub-directories, or a set of files specified by one or more FileSets. -When specifying a set of files, empty directories are not removed.

+When specifying a set of files, empty directories are not removed by default. +To remove empty directories, use the includeEmptyDirs atribute.

Parameters

@@ -2109,6 +2110,12 @@ When specifying a set of files, empty directories are not removed.

Default is "false" meaning things are "noisy". + + + + +
No
includeEmptyDirsSet to "true" to delete empty directores when + using filesets. Default is "false".No
includes Deprecated. Comma separated list of patterns of files that must be @@ -2145,13 +2152,20 @@ When specifying a set of files, empty directories are not removed.

  <delete file="/lib/ant.jar"/>

deletes the file /lib/ant.jar.

  <delete dir="lib"/>
-

deletes all files in the /lib directory.

+

deletes the lib directory, including all files +and subdirectories of lib.

  <delete>
     <fileset dir="." includes="**/*.bak"/>
   </delete>
 

deletes all files with the extension ".bak" from the current directory and any sub-directories.

+
  <delete includeEmptyDirs="true" >
+    <fileset dir="build" />
+  </delete>
+
+

deletes all files and subdirectories of build, but not +build itself.


Deltree

Deprecated

diff --git a/src/main/org/apache/tools/ant/taskdefs/Delete.java b/src/main/org/apache/tools/ant/taskdefs/Delete.java index e80b0892a..495f4809e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Delete.java +++ b/src/main/org/apache/tools/ant/taskdefs/Delete.java @@ -79,6 +79,7 @@ public class Delete extends MatchingTask { protected File dir = null; protected Vector filesets = new Vector(); protected boolean usedMatchingTask = false; + protected boolean includeEmpty = false; // by default, remove matching empty dirs private int verbosity = Project.MSG_VERBOSE; private boolean quiet = false; @@ -128,6 +129,13 @@ public class Delete extends MatchingTask { } /** + * Used to delete empty directories. + */ + public void setIncludeEmptyDirs(boolean includeEmpty) { + this.includeEmpty = includeEmpty; + } + + /** * Adds a set of files (nested fileset attribute). */ public void addFileset(FileSet set) { @@ -234,7 +242,7 @@ public class Delete extends MatchingTask { } else { log("Deleting: " + file.getAbsolutePath()); - if (!quiet && !file.delete()) { + if (!file.delete() && !quiet) { throw new BuildException("Unable to delete file " + file.getAbsolutePath()); } } @@ -245,7 +253,15 @@ public class Delete extends MatchingTask { // delete the directory if (dir != null && dir.exists() && dir.isDirectory() && !usedMatchingTask) { - log("Deleting directory " + dir.getAbsolutePath()); + /* + If verbosity is MSG_VERBOSE, that mean we are doing regular logging + (backwards as that sounds). In that case, we want to print one + message about deleting the top of the directory tree. Otherwise, + the removeDir method will handle messages for _all_ directories. + */ + if (verbosity == Project.MSG_VERBOSE) { + log("Deleting directory " + dir.getAbsolutePath()); + } removeDir(dir); } @@ -254,14 +270,16 @@ public class Delete extends MatchingTask { FileSet fs = (FileSet) filesets.elementAt(i); DirectoryScanner ds = fs.getDirectoryScanner(project); String[] files = ds.getIncludedFiles(); - removeFiles(fs.getDir(project), files); + String[] dirs = ds.getIncludedDirectories(); + removeFiles(fs.getDir(project), files, dirs); } // delete the files from the default fileset if (usedMatchingTask && dir != null) { DirectoryScanner ds = super.getDirectoryScanner(dir); - String [] files = ds.getIncludedFiles(); - removeFiles(dir, files); + String[] files = ds.getIncludedFiles(); + String[] dirs = ds.getIncludedDirectories(); + removeFiles(dir, files, dirs); } } @@ -279,28 +297,50 @@ public class Delete extends MatchingTask { removeDir(f); } else { log("Deleting " + f.getAbsolutePath(), verbosity); - if (!quiet && !f.delete()) { + if (!f.delete() && !quiet) { throw new BuildException("Unable to delete file " + f.getAbsolutePath()); } } } log("Deleting directory " + d.getAbsolutePath(), verbosity); - if (!quiet && !d.delete()) { + if (!d.delete() && !quiet) { throw new BuildException("Unable to delete directory " + dir.getAbsolutePath()); } } - protected void removeFiles(File d, String[] files) { + protected void removeFiles(File d, String[] files, String[] dirs) { if (files.length > 0) { log("Deleting " + files.length + " files from " + d.getAbsolutePath()); for (int j=0; j 0 && includeEmpty) { + int dirCount = 0; + for (int j=0; j 0) { + log("Deleted " + dirCount + " director" + + (dirCount==1 ? "y" : "ies") + + " from " + d.getAbsolutePath()); + } + } } }