Java File Path Delete deleteDirWithContent(final String path)

Here you can find the source of deleteDirWithContent(final String path)

Description

delete Dir With Content

License

Apache License

Declaration

public static boolean deleteDirWithContent(final String path) 

Method Source Code

//package com.java2s;
/*// ww w  .  j  a va2  s  .  c  om
 * Copyright 2016 IKS Gesellschaft fuer Informations- und Kommunikationssysteme mbH
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;

public class Main {
    public static boolean deleteDirWithContent(final String path) {
        final File dir = new File(path);
        return deleteDirWithContent(dir);
    }

    public static boolean deleteDirWithContent(final File dir) {
        boolean ok = true;
        if (dir.exists() && dir.isDirectory()) {
            final File[] listFiles = dir.listFiles();
            for (int i = 0; i < listFiles.length; i++) {
                if (listFiles[i].isDirectory()) {
                    deleteDirWithContent(listFiles[i]);
                } else {
                    boolean b = listFiles[i].delete();
                    if (ok)
                        ok = b;
                }
            }
            boolean b = dir.delete();
            if (ok)
                ok = b;
        }
        return ok;
    }
}

Related

  1. deleteDirectoryTree(String directoryPath)
  2. deleteDirRecursive(String dirPath)
  3. deleteDirRecursive(String path)
  4. deleteDirs(File path)
  5. deleteDirs(String pathname)
  6. deleteEmptDir(String Path, String username)
  7. deleteEmptyDir(File dstPath)
  8. deleteEmptyParents(final File path)
  9. deleteFile(File path)