Java File Path Delete deleteDir(File directory)

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

Description

delete Dir

License

GNU General Public License

Declaration

public static boolean deleteDir(File directory) 

Method Source Code


//package com.java2s;
/*//  www . j  a va 2 s . co m
 * Copyright 2008 brunella ltd
 *
 * Licensed under the GPL Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

import java.io.*;

public class Main {
    public static boolean deleteDir(File directory) {
        boolean ok = true;
        File[] children = directory.listFiles();
        if (children != null) {
            for (File file : children) {
                if (!file.isDirectory()) {
                    ok = ok && file.delete();
                } else {
                    ok = ok && deleteDir(file);
                }
            }
        }
        ok = ok && directory.delete();
        return ok;
    }
}

Related

  1. deleteDir(File dir, int depth, boolean deleteRootDirectory)
  2. deleteDir(File dir, String dirPath)
  3. deleteDir(File directory)
  4. deleteDir(File directory)
  5. deleteDir(File directory)
  6. deleteDir(File directory, boolean removeAll)
  7. deleteDir(File dirFile)
  8. deleteDir(File dirPath)
  9. deleteDir(File f)