ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Forceable directory deletion
Date Fri, 16 Aug 2002 22:11:52 GMT
Something like below. --DD

  /**
   * Deletes a single file, or a file hierarchy below a directory.
   * <p>
   * {@link File#delete()} works only for files and empty directories.
   * This method recurses on this file's children, if any, to remove
   * a non-empty directory.
   * <p>
   * <em>Note that the Windows operating system tends to lock files or
   * directories often, and thus can lead to failure when attempted to
   * delete such locked files or directories!</em>
   *
   * @param  the file or directory to remove.
   * @return <code>true</code> if successfully removed;
   *         <code>false</code> otherwise.
   */
  public static boolean deleteFile(File file) {
    boolean rc = true;
    if (file.isDirectory()) {
      File[] files = file.listFiles();
      if (files==null) {
        return false;
      }
      for (int i=0; rc && i<files.length; ++i) {
        if (files[i].isDirectory()) {
          rc = deleteFile(files[i]);
        }
        else {
          rc = files[i].delete();
        }
      }
    }
    return rc && file.delete();
  }

-----Original Message-----
From: jlcarpenter@household.com [mailto:jlcarpenter@household.com] 
Sent: Friday, August 16, 2002 5:09 PM
To: Ant Developers List
Subject: Forceable directory deletion


File dir = new File("some/dir/path");
boolean deleteSuccess = dir.delete();

Only deletes empty directories.

What file/directory utility can be used to forceably delete a directory?

James Lee Carpenter
Software Engineer
Household Technical Services
6602 Convoy Court
San Diego, CA 92111

ph: 858-609-2461
email: jlcarpenter@household.com



--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message