Java Recursive Delete recursiveDelete(File _f)

Here you can find the source of recursiveDelete(File _f)

Description

recursive Delete

License

Open Source License

Declaration

public static boolean recursiveDelete(File _f) throws IOException 

Method Source Code

//package com.java2s;
/* /*from   www.  java2  s . c  o m*/
 *  Copyright (C) 2012 AW2.0 Ltd
 *
 *  org.aw20 is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  Free Software Foundation,version 3.
 *  
 *  OpenBD 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 org.aw20.  If not, see http://www.gnu.org/licenses/
 *  
 *  Additional permission under GNU GPL version 3 section 7
 *  
 *  If you modify this Program, or any covered work, by linking or combining 
 *  it with any of the JARS listed in the README.txt (or a modified version of 
 *  (that library), containing parts covered by the terms of that JAR, the 
 *  licensors of this Program grant you additional permission to convey the 
 *  resulting work. 
 *  
 *  $Id: FileUtil.java 2981 2012-08-08 21:01:27Z alan $
 */

import java.io.File;

import java.io.IOException;

public class Main {
    public static boolean recursiveDelete(File _f) throws IOException {
        boolean result = true;
        File[] dirContent = _f.listFiles();
        if (dirContent != null) { // will be null if it's not a directory
            for (int i = 0; i < dirContent.length; i++) {
                if (dirContent[i].isDirectory()) {
                    if (!recursiveDelete(dirContent[i])) {
                        result = false;
                    }
                } else if (!dirContent[i].delete()) {
                    result = false;
                }
            }

            if (!_f.delete()) {
                result = false;
            }
        }

        return result;
    }
}

Related

  1. recursiveDel(final File f)
  2. recursiveDelete(File base)
  3. recursiveDelete(File dir)
  4. recursiveDelete(File dir)
  5. recursiveDelete(File dir)