I try to remove file in directory without file which path is in my array
public static boolean deleteDir(File dir, List<String> exclusionList) throws IOException {
if (exclusionList != null && exclusionList.contains(dir.getCanonicalPath())) { // skip file
System.out.println("Skipped: " + dir.getCanonicalPath());
return true;
}
System.out.println("Deleting: " + dir.getCanonicalPath());
if (dir.isDirectory()) {
File[] children = dir.listFiles();
boolean success = true;
for (File element : children) {
if (!deleteDir(element, exclusionList)) {
success = false;
}
}
return success;
}
return dir.delete();
}
this is my function to delete and is work fine to delete file like .txt .yml etc but when it must delete folder(folder content remove perflecty) but folder is exists, and i have a lot of empty folders ;/