Java Delete Directory Recursively deleteDirectoryRecursivly(File directory)

Here you can find the source of deleteDirectoryRecursivly(File directory)

Description

delete Directory Recursivly

License

Open Source License

Declaration

public static boolean deleteDirectoryRecursivly(File directory) 

Method Source Code


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

import java.io.File;

public class Main {
    public static boolean deleteDirectoryRecursivly(File directory) {
        String[] list = directory.list();
        if (list != null) {
            for (String entryName : list) {
                File entry = new File(directory, entryName);
                if (entry.isDirectory()) {
                    if (!deleteDirectoryRecursivly(entry)) {
                        return false;
                    }/*from  ww w  .j  av  a 2s  .c o  m*/
                } else {
                    if (!entry.delete()) {
                        return false;
                    }
                }
            }
        }
        if (!directory.delete()) {
            return false;
        }
        return true;
    }
}

Related

  1. deleteDirectoryRecursive(File directory)
  2. deleteDirectoryRecursive(File f)
  3. deleteDirectoryRecursively(File rootFile)
  4. deleteDirectoryRecursively(File toDelete)
  5. deleteDirectoryRecursivelyE(File dir)
  6. deleteDirRecursive(File aDir)
  7. deleteDirRecursively(File dir)
  8. deleteDirRecursively(File directory)