Java Utililty Methods Delete Directory

List of utility methods to do Delete Directory

Description

The list of methods to do Delete Directory are organized into topic(s).

Method

voiddeleteFiles(File directory)
Non-recursive delete for all files in the given directory.
if (directory.isDirectory()) {
    String[] children = directory.list();
    for (int i = 0; i < children.length; i++) {
        new File(directory, children[i]).delete();
voiddeleteFiles(File directory, String prefix)
Delete all the files and sub directories which matches given prefix in a given directory.
if (directory.isDirectory()) {
    for (File f : directory.listFiles()) {
        if (f.getName().startsWith(prefix)) {
            deleteDirectory(f);
voiddeleteFiles(File docFolder)
ftang Comment method "deleteFiles".
if (docFolder.listFiles() == null || docFolder.listFiles().length == 0) {
    docFolder.delete();
} else {
    for (File file : docFolder.listFiles()) {
        if (file.isFile()) {
            file.delete();
        } else if (file.isDirectory()) {
            deleteFiles(file);
...
booleandeleteFiles(File f, boolean del_self)
deletes all directory's content if it is a directory deletes all subfiles, subdirectories ...
boolean rez = true;
if (f.exists()) {
    if (f.isDirectory()) {
        File[] files = f.listFiles();
        for (File file : files) {
            rez = deleteFiles(file, true) & rez;
        if (del_self) {
...
voiddeleteFiles(File file)
Remove com recursividade.
File[] listFiles = file.listFiles();
Stream.of(listFiles).parallel().forEach(f -> {
    if (f.isDirectory()) {
        deleteFiles(f);
    f.delete();
});
voiddeleteFiles(File folder)
delete Files
if (folder != null) {
    File[] files = folder.listFiles();
    if (files != null) {
        for (File file : files) {
            delete(file);
booleandeleteFiles(File folder)
delete Files
if (folder == null)
    return false;
if (!folder.exists() || !folder.isDirectory()) {
    return false;
for (File file : getFiles(folder)) {
    file.delete();
return true;
voiddeleteFiles(File parent, boolean incParent)
deletes files recursively.
if (!parent.exists()) {
    throw new FileNotFoundException("File does not exist.");
if (parent.isDirectory() && !(parent.listFiles() == null)) {
    File[] files = parent.listFiles();
    for (int i = 0; i < files.length; i++) {
        deleteFiles(files[i], true);
if (incParent) {
    parent.delete();
booleandeleteFiles(File[] files)
Delete the files and folders passed as parameter.
boolean result = true;
for (int i = 0; i < files.length; i++) {
    if (files[i].isDirectory()) {
        result = deleteFiles(files[i].listFiles()) && files[i].delete();
    } else {
        if (files[i].exists()) {
            result = files[i].delete();
return result;
voiddeleteFiles(File[] files)
delete Files
for (File file : files) {
    if (file.isDirectory()) {
        deleteFolder(file);
    } else {
        file.delete();