public static void deleteFolder(String folder){
File f = new File(folder);
if(!f.exists()){
return;
}
if(f.isFile()){
System.out.println("删除文件"+f.getPath());
System.out.println("删除文件状态"+f.delete());
return;
}
if(f.isDirectory()){
File[] _f = f.listFiles();
for(File __f:_f){
if(__f.isFile()) {
System.out.println("删除文件"+__f.getPath());
System.out.println("删除文件状态"+__f.delete());
}
if(__f.isDirectory()){
deleteFolder(__f.getPath());
}
}
File[] _f2 = f.listFiles();
if(_f2.length == 0){
System.out.println("删除目录"+f.getPath());
System.out.println("删除目录"+f.delete());
}
}
}
public static void deleteFolder(String folder,String root){
File f = new File(folder);
if(!f.exists()){
return;
}
if(f.isFile()){
System.out.println("删除文件"+f.getPath());
System.out.println("删除文件状态"+f.delete());
return;
}
if(f.isDirectory()){
File[] _f = f.listFiles();
for(File __f:_f){
if(__f.isFile()) {
System.out.println("删除文件"+__f.getPath());
System.out.println("删除文件状态"+__f.delete());
}
if(__f.isDirectory()){
deleteFolder(__f.getPath(),root);
}
}
File[] _f2 = f.listFiles();
if(_f2.length == 0 && !root.equals(f.getPath())){
System.out.println("删除目录"+f.getPath());
System.out.println("删除目录"+f.delete());
}
}
}