01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2005 Emic Networks.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: * Initial developer(s): Emmanuel Cecchet.
19: * Contributor(s): ______________________.
20: */package org.continuent.sequoia.common.util;
21:
22: import java.io.File;
23:
24: /**
25: * This class defines a FileManagement that provides tools to manage files and
26: * directories.
27: *
28: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet</a>
29: * @version 1.0
30: */
31: public class FileManagement {
32:
33: /**
34: * Delete a directory by deleting recursively all sub files.
35: *
36: * @param dir directoty to delete
37: * @return true if success, false otherwise
38: */
39: public static final boolean deleteDir(File dir) {
40: if (dir.isDirectory()) {
41: String[] children = dir.list();
42: for (int i = 0; i < children.length; i++) {
43: boolean success = deleteDir(new File(dir, children[i]));
44: if (!success) {
45: return false;
46: }
47: }
48: }
49: // The directory is now empty so delete it
50: return dir.delete();
51: }
52:
53: }
|