01: // Copyright (c) 2004 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.common;
12:
13: import java.io.File;
14:
15: import java.util.logging.Logger;
16:
17: /**
18: * DOCUMENT ME!
19: *
20: * @author Ramesh
21: */
22: public class DirectoryHelper {
23: /**
24: *
25: */
26: /**
27: *
28: */
29: /**
30: *
31: */
32: /**
33: *
34: */
35: /**
36: *
37: */
38: /**
39: *
40: */
41:
42: /**
43: *
44: */
45: private static Logger sLog = Logger
46: .getLogger("com.sun.jbi.binding.jms.util");
47:
48: /**
49: * Deletes a directory recursively.
50: *
51: * @param directoryOrFile directory or file that has to be deleted.
52: */
53: public static void deleteRecursively(File directoryOrFile) {
54: if (directoryOrFile == null) {
55: return;
56: }
57:
58: File directory = directoryOrFile;
59:
60: try {
61: if (directory.isFile()) {
62: directory.delete();
63:
64: return;
65: }
66:
67: File[] fileList = directory.listFiles();
68:
69: if (fileList == null) {
70: return;
71: }
72:
73: if (fileList.length == 0) {
74: directory.delete();
75:
76: return;
77: } else {
78: for (int i = 0; i < fileList.length; i++) {
79: if (fileList[i].isFile()) {
80: fileList[i].delete();
81: }
82:
83: if (fileList[i].isDirectory()) {
84: deleteRecursively(fileList[i]);
85: }
86: }
87:
88: directory.delete();
89:
90: return;
91: }
92: } catch (Exception e) {
93: sLog.info(directory.getAbsolutePath() + " "
94: + e.getMessage());
95: }
96:
97: return;
98: }
99: }
|