刪除指定文件夾下所有.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<File> listSVNFile = new ArrayList<File>();
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<File> 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);
}
}
}
}
}
}