01: // Copyright (c) 2004-2005 Sun Microsystems Inc., All Rights Reserved.
02:
03: /*
04: * DirectoryHelper.java
05: *
06: * SUN PROPRIETARY/CONFIDENTIAL.
07: * This software is the proprietary information of Sun Microsystems, Inc.
08: * Use is subject to license terms.
09: *
10: */
11: package com.sun.jbi.engine.sequencing.util;
12:
13: import java.io.File;
14:
15: import java.util.logging.Logger;
16:
17: /**
18: * DirectoryHelper.
19: *
20: * @author Sun Microsystems, Inc.
21: */
22: public class DirectoryHelper {
23: /**
24: * Logger object.
25: */
26: private static Logger sLog = Logger
27: .getLogger("com.sun.jbi.engine.sequencing.util");
28:
29: /**
30: * Deletes a directory recursively.
31: *
32: * @param directoryOrFile a directory or file name
33: */
34: public static void deleteRecursively(File directoryOrFile) {
35: if (directoryOrFile == null) {
36: return;
37: }
38:
39: File directory = directoryOrFile;
40:
41: try {
42: if (directory.isFile()) {
43: directory.delete();
44:
45: return;
46: }
47:
48: File[] fileList = directory.listFiles();
49:
50: if (fileList == null) {
51: return;
52: }
53:
54: if (fileList.length == 0) {
55: directory.delete();
56:
57: return;
58: } else {
59: for (int i = 0; i < fileList.length; i++) {
60: if (fileList[i].isFile()) {
61: fileList[i].delete();
62: }
63:
64: if (fileList[i].isDirectory()) {
65: deleteRecursively(fileList[i]);
66: }
67: }
68:
69: directory.delete();
70:
71: return;
72: }
73: } catch (Exception e) {
74: sLog.info("Could not Remove file "
75: + directory.getAbsolutePath()
76: + "Please remove it Manually");
77: }
78:
79: return;
80: }
81: }
|