public void deleteDir() throws IOException {
Files.walk(Paths.get("D:\\aaa\\xxx"))
.sorted(Comparator.reverseOrder())
.filter(Files::isDirectory)
.forEach(path -> {
if (path.toFile().list().length == 0) {
// Delete the empty directory
path.toFile().delete();
System.out.println("Directory deleted successfully"+path.toString());
} else {
System.out.println("Directory is not empty"+path.toString());
}
});
}
删除xxx目录下的所有非空文件夹及子文件夹,文件夹中有文件的不删除