删除指定文件夹下所有.svn文件夹:
package zzu.wtb.deleteSVN;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class DeleteSVN {
private int wjjgs = 0;
private int wjgs = 0;
private List listSVNFile = new ArrayList();
public static void main(String[] args) {
DeleteSVN ds = new DeleteSVN();
File f = new File("C:\\Users\\Administrator\\Desktop\\sharesoftware");
for(File file : ds.getSVNFile(f)){
ds.deleteFile(file);
}
System.out.println("删除文件总数为:"+(ds.wjgs+ds.wjjgs)+"个,\n其中包括:");
System.out.println("文件:"+ds.wjgs+"个,\n文件夹:"+ds.wjjgs+"个。");
}
//获得f文件下所有.svn文件
public List getSVNFile(File f) {
File[] fs = f.listFiles();
for (int k = 0; k < fs.length; k++) {
if (".svn".equals(fs[k].getName())) {
listSVNFile.add(fs[k]);
} else if (fs[k].isDirectory()) {
getSVNFile(fs[k]);
}
}
return listSVNFile;
}
//删除目录
public void deleteFile(File file) {
while(file.exists()){
if(file.isFile()){
if(file.delete()){
System.out.println("文件:"+file.getAbsolutePath());
wjgs++;
}
deleteFile(file);
}else{
if(file.listFiles().length == 0){
if(file.delete()){
System.out.println("文件夹:"+file.getAbsolutePath());
wjjgs++;
}
}else{
File[] fs = file.listFiles();
for(File ff: fs){
deleteFile(ff);
}
}
}
}
}
}