Java File Path Delete deleteDir(File dir)

Here you can find the source of deleteDir(File dir)

Description

Loescht das angegebene Verzeichnis inkl.

License

Open Source License

Parameter

Parameter Description
dir Verzeichnis

Return

Erfolgs-Kennzeichen.

Declaration

public static boolean deleteDir(File dir) 

Method Source Code

//package com.java2s;
/*//from   w w  w.ja va 2s.  c  o m
 * Copyright 2005-2008 by beck et al. projects GmbH, Munich
 * Copyright 2009 by Kappich Systemberatung, Aachen
 * 
 * This file is part of de.bsvrz.sys.funclib.losb.
 * 
 * de.bsvrz.sys.funclib.losb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * de.bsvrz.sys.funclib.losb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with de.bsvrz.sys.funclib.losb.  If not, see <http://www.gnu.org/licenses/>.
    
 * Contact Information:
 * Kappich Systemberatung
 * Martin-Luther-Stra?e 14
 * 52062 Aachen, Germany
 * phone: +49 241 4090 436 
 * mail: <info@kappich.de>
 */

import java.io.File;
import java.io.FileFilter;

public class Main {
    /**
     * Loescht das angegebene Verzeichnis inkl. seines Inhalts rekursiv.
     *
     * @param dir Verzeichnis
     *
     * @return Erfolgs-Kennzeichen.
     */
    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            for (File f : dir.listFiles()) {
                if (!deleteDir(f))
                    return false;
            }
        }
        return dir.delete();
    }

    /**
     * Liefert eine Array aller Dateien (ohne Unterverzeichnisse) des angegebenen Verzeichnisses.
     *
     * @param dir Verzeichnis
     *
     * @return Array von Dateien
     */
    public static File[] listFiles(File dir) {
        return dir.listFiles(new FileFilter() {
            public boolean accept(File f) {
                return f.isFile();
            }
        });
    }
}

Related

  1. deleteContentsOnly(final String srcPath)
  2. deleteDataFiles(final Collection paths)
  3. deleteDb(String path)
  4. deleteDir(File delDir)
  5. deleteDir(File dir)
  6. deleteDir(File dir)
  7. deleteDir(File dir)
  8. deleteDir(File dir)
  9. deleteDir(File dir)