1 package net.obsearch.index.utils; 2 3 import java.io.File; 4 import java.io.IOException; 5 6 /* 7 OBSearch: a distributed similarity search engine 8 This project is to similarity search what 'bit-torrent' is to downloads. 9 Copyright (C) 2007 Arnoldo Jose Muller Molina 10 11 This program is free software: you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation, either version 3 of the License, or 14 (at your option) any later version. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 /** 25 * Utility class to manipulate directories. 26 * @author Arnoldo Jose Muller Molina 27 * @since 0.7 28 */ 29 30 public final class Directory { 31 32 /** 33 * Utility classes should not have private constructors. 34 */ 35 private Directory() { 36 37 } 38 39 /** 40 * Delete the given directory and all its contents. 41 * @param dbFolder The directory to delete. 42 * @throws IOException If the operation is not succesful. 43 */ 44 public static void deleteDirectory(File dbFolder) throws IOException { 45 if (!dbFolder.exists()) { 46 return; 47 } 48 File[] files = dbFolder.listFiles(); 49 for (File f : files) { 50 if (f.isDirectory()) { 51 deleteDirectory(f); 52 } else { 53 if(f.toString().endsWith(".java")){ 54 throw new IOException("Cannot delete .java files!!!"); 55 } 56 if (!f.delete()) { 57 throw new IOException("Could not delete: " + f); 58 } 59 } 60 } 61 if (!dbFolder.delete()) { 62 throw new IOException("Could not delete: " + dbFolder); 63 } 64 if (dbFolder.exists()) { 65 throw new IOException("Could not delete: " + dbFolder); 66 } 67 } 68 69 }