From a432cad4ed1ed0a83e0109f1e1eac3c1caf59979 Mon Sep 17 00:00:00 2001 From: mdb Date: Fri, 23 May 2003 18:13:36 +0000 Subject: [PATCH] Added a recursive delete alternative that doesn't delete the top directory. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1137 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/FileUtil.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/FileUtil.java b/projects/samskivert/src/java/com/samskivert/util/FileUtil.java index 53749e4a..1d71fccf 100644 --- a/projects/samskivert/src/java/com/samskivert/util/FileUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/FileUtil.java @@ -1,5 +1,5 @@ // -// $Id: FileUtil.java,v 1.1 2003/05/03 00:50:57 ray Exp $ +// $Id: FileUtil.java,v 1.2 2003/05/23 18:13:36 mdb Exp $ package com.samskivert.util; @@ -17,15 +17,32 @@ public class FileUtil * directories underneath it. */ public static void recursiveDelete (File file) + { + recursiveWipe(file, false); + } + + /** + * Recursively deletes all of the files and directories in the + * supplied directory, but not the directory itself. + */ + public static void recursiveClean (File file) + { + recursiveWipe(file, false); + } + + /** Helper function. */ + protected static void recursiveWipe (File file, boolean wipeMe) { if (file.isDirectory()) { File[] files = file.listFiles(); for (int ii = 0; ii < files.length; ii++) { - recursiveDelete(files[ii]); + recursiveWipe(files[ii], true); } } - if (!file.delete()) { - Log.warning("Failed to delete " + file + "."); + if (wipeMe) { + if (!file.delete()) { + Log.warning("Failed to delete " + file + "."); + } } } }