Java Delete Folder deleteFolder(File file)

Here you can find the source of deleteFolder(File file)

Description

Used to delete a folder.

License

BSD License

Parameter

Parameter Description
file The folder to delete.

Return

true if the folder was successfully deleted.

Declaration

public static boolean deleteFolder(File file) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Multiverse 2 Copyright (c) the Multiverse Team 2011.                       *
 * Multiverse 2 is licensed under the BSD License.                            *
 * For more information please check the README.md file included              *
 * with this project.                                                         *
 ******************************************************************************/

import java.io.File;

public class Main {
    /**//  w w w. ja  v a 2s. com
     * Used to delete a folder.
     *
     * @param file The folder to delete.
     * @return true if the folder was successfully deleted.
     */
    public static boolean deleteFolder(File file) {
        if (file.exists()) {
            boolean ret = true;
            // If the file exists, and it has more than one file in it.
            if (file.isDirectory()) {
                for (File f : file.listFiles()) {
                    ret = ret && deleteFolder(f);
                }
            }
            return ret && file.delete();
        } else {
            return false;
        }
    }
}

Related

  1. deleteFolder(@Nonnull File file)
  2. deleteFolder(File dir, boolean deleteFolderItself)
  3. deleteFolder(File file)
  4. deleteFolder(File file)
  5. deleteFolder(File file, boolean deleteParent)
  6. deleteFolder(File file, boolean withCurrentFolder)
  7. deleteFolder(File folder)
  8. deleteFolder(File folder)