Java File Path Delete deleteDir(File dir)

Here you can find the source of deleteDir(File dir)

Description

deletes all Files and Subfolders in a directory

License

Open Source License

Parameter

Parameter Description
dir target directory

Declaration

public static boolean deleteDir(File dir) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.io.File;

public class Main {
    /**/*from   w w w  . j a v a 2  s  . c  om*/
    * deletes all Files and Subfolders in a directory
    * @param dir target directory
    * @return
    */
    public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] entries = dir.list();
            for (int x = 0; x < entries.length; x++) {
                File aktFile = new File(dir.getPath(), entries[x]);
                deleteDir(aktFile);
            }
            if (dir.delete()) {
                return true;
            } else {
                return false;
            }
        } else {
            if (dir.delete()) {
                return true;
            } else {
                return false;
            }
        }
    }
}

Related

  1. deleteDir(File dir)
  2. deleteDir(File dir)
  3. deleteDir(File dir)
  4. deleteDir(File dir)
  5. deleteDir(File dir)
  6. deleteDir(File dir)
  7. deleteDir(File dir)
  8. deleteDir(File dir)
  9. deleteDir(File dir)