Java Delete Folder deleteFolder(final File folder)

Here you can find the source of deleteFolder(final File folder)

Description

Deletes a folder by individually deleting each file and subfolder folder.

License

Open Source License

Parameter

Parameter Description
folder the folder to be deleted

Return

true of the folder was deleted successfully

Declaration

static boolean deleteFolder(final File folder) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    /**//from ww  w.  j  a va2  s  .c  om
     * Deletes a folder by individually deleting each file and
     * subfolder folder.
     * 
     * @param folder the folder to be deleted
     * @return true of the folder was deleted successfully
     */
    static boolean deleteFolder(final File folder) {
        boolean success = false;
        if (folder.isDirectory()) {
            for (final File file : folder.listFiles()) {
                if (file.isDirectory()) {
                    deleteFolder(file);
                } else {
                    file.delete();
                }
            }
            success = folder.delete();
        }

        return success;
    }
}

Related

  1. deleteFolder(File folder)
  2. deleteFolder(File folder)
  3. deleteFolder(File folder)
  4. deleteFolder(File folder)
  5. deleteFolder(File folder)
  6. deleteFolder(final File folder)
  7. deleteFolder(final String folder)
  8. deleteFolder(String folder)
  9. deleteFolder(String folder)