01: package dalma.impl;
02:
03: import java.io.File;
04: import java.io.IOException;
05:
06: /**
07: * @author Kohsuke Kawaguchi
08: */
09: public class Util {
10: /**
11: * Deletes the contents of the given directory (but not the directory itself)
12: * recursively.
13: *
14: * @throws IOException
15: * if the operation fails.
16: */
17: public static void deleteContentsRecursive(File file)
18: throws IOException {
19: File[] files = file.listFiles();
20: if (files == null)
21: return; // non existent
22: for (File child : files) {
23: if (child.isDirectory())
24: deleteContentsRecursive(child);
25: if (!child.delete())
26: throw new IOException("Unable to delete "
27: + child.getPath());
28: }
29: }
30:
31: public static void deleteRecursive(File dir) throws IOException {
32: if (!dir.exists())
33: return;
34:
35: deleteContentsRecursive(dir);
36: if (!dir.delete())
37: throw new IOException("Unable to delete " + dir);
38: }
39: }
|