Java Delete Directory deleteDirectory(File f)

Here you can find the source of deleteDirectory(File f)

Description

Borra todos los ficheros contenidos en un directorio.

License

Open Source License

Parameter

Parameter Description
f El directorio a borrar.

Declaration

public static void deleteDirectory(File f) 

Method Source Code

//package com.java2s;
/*//from   ww w .  j  a  v  a  2 s . c  om
 * ISABEL: A group collaboration tool for the Internet
 * Copyright (C) 2009 Agora System S.A.
 * 
 * This file is part of Isabel.
 * 
 * Isabel is free software: you can redistribute it and/or modify
 * it under the terms of the Affero GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Isabel 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
 * Affero GNU General Public License for more details.
 * 
 * You should have received a copy of the Affero GNU General Public License
 * along with Isabel.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;

public class Main {
    /**
     * Borra todos los ficheros contenidos en un directorio.
     * @param f El directorio a borrar.
     */
    public static void deleteDirectory(File f) {
        // Listo los ficheros del directorio
        File[] contents = f.listFiles();

        // Borro cada fichero contenido
        // utilizando deleteDirectory si es un directorio.
        for (int i = 0; i < contents.length; i++) {
            if (contents[i].isDirectory())
                deleteDirectory(contents[i]);
            contents[i].delete();
        }
        // Finalmente no borro el propio directorio
        //f.delete();
    }
}

Related

  1. deleteDirectory(File directory)
  2. deleteDirectory(File directory)
  3. deleteDirectory(File directory)
  4. deleteDirectory(File directory)
  5. deleteDirectory(File directory, boolean ignoreErrors)
  6. deleteDirectory(File f)
  7. deleteDirectory(File f)
  8. deleteDirectory(File f)
  9. deleteDirectory(File file)