Java Recursive Delete recursiveDelete(File file, boolean deleteParentFile)

Here you can find the source of recursiveDelete(File file, boolean deleteParentFile)

Description

Recursively deletes a file (folder) and all children

License

Apache License

Parameter

Parameter Description
file a parameter
deleteParentFile Whether or not to delete the top level

Declaration

public static void recursiveDelete(File file, boolean deleteParentFile) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**/*w w w.  j a  va2s .c  o  m*/
     * Recursively deletes a file (folder) and all children
     *
     * @param file
     * @see #recursiveDelete(java.io.File,boolean)
     */
    public static void recursiveDelete(File file) {
        recursiveDelete(file, true);
    }

    /**
     * Recursively deletes a file (folder) and all children
     *
     * @param file
     * @param deleteParentFile Whether or not to delete the top level
     */
    public static void recursiveDelete(File file, boolean deleteParentFile) {
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            File file1 = files[i];
            if (file1.isDirectory()) {
                recursiveDelete(file1);
            } else {
                file1.delete();
            }
        }
        if (deleteParentFile) {
            file.delete();
        }
    }
}

Related

  1. recursiveDelete(File file)
  2. recursiveDelete(File file)
  3. recursiveDelete(File file)
  4. recursiveDelete(File file)
  5. recursiveDelete(File file)
  6. recursiveDelete(File fileOrDir)
  7. recursiveDelete(File fileOrDir)
  8. recursiveDelete(File folder)
  9. recursiveDelete(File parent)