KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > util > FileManagement


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2005 Emic Networks.
4  * Contact: c-jdbc@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  *
20  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): ______________________.
22  */

23
24 package org.objectweb.cjdbc.common.util;
25
26 import java.io.File JavaDoc;
27
28 /**
29  * This class defines a FileManagement that provides tools to manage files and
30  * directories.
31  *
32  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet</a>
33  * @version 1.0
34  */

35 public class FileManagement
36 {
37
38   /**
39    * Delete a directory by deleting recursively all sub files.
40    *
41    * @param dir directoty to delete
42    * @return true if success, false otherwise
43    */

44   public static final boolean deleteDir(File JavaDoc dir)
45   {
46     if (dir.isDirectory())
47     {
48       String JavaDoc[] children = dir.list();
49       for (int i = 0; i < children.length; i++)
50       {
51         boolean success = deleteDir(new File JavaDoc(dir, children[i]));
52         if (!success)
53         {
54           return false;
55         }
56       }
57     }
58     // The directory is now empty so delete it
59
return dir.delete();
60   }
61
62 }
63
Popular Tags