Java Delete Folder deleteFolder(File file, boolean withCurrentFolder)

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

Description

Delete the sub folders, if true, will delete current folder also.

License

Open Source License

Declaration

public static void deleteFolder(File file, boolean withCurrentFolder) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.io.File;

public class Main {
    /**/* w w w .  j  a  v a2s.  c o  m*/
     * 
     * Delete the sub folders, if true, will delete current folder also.
     */
    public static void deleteFolder(File file, boolean withCurrentFolder) {
        if (file.exists() && file.isDirectory()) {
            File files[] = file.listFiles();
            for (File file2 : files) {
                deleteFile(file2, true);
            }
            if (withCurrentFolder) {
                file.delete();
            }
        }
    }

    public static void deleteFile(File file, boolean delete) {
        if (file.exists()) {
            if (file.isFile() && delete) {
                file.delete();
            } else if (file.isDirectory()) {
                File files[] = file.listFiles();
                for (File file2 : files) {
                    deleteFile(file2, true);
                }
            }
            if (delete) {
                file.delete();
            }
        }
    }
}

Related

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