package com.heima.test;
import java.io.File;
import java.io.FileFilter;
public class DeleteEmptyFolder {
// 删除一个文件夹内所有空文件夹
// private static int count = 0;
public static void deleteEmptyFolder(File file) {
if (file.isDirectory() && file.list().length == 0) {
file.delete();
} else {
File[] files = file.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory();
}
});
for (File file2 : files) {
deleteEmptyFolder(file2);
file2.delete();
}
}
// System.out.println("执行"+(++count)+"次");
}
public static void main(String[] args) {
File file = new File("E:\\AA");
deleteEmptyFolder(file);
}
}
|
|