有时我们想清理svn工程流下来的标记,其实只要删掉每个文件夹里面的.svn文件就可以,不过工作太繁琐,就交给程序来处理,遍历一遍文件夹,清理掉.svn。
package tool;
import java.io.*;
/**
* 清理svn
* @author Administrator
*
*/
public class FilterSVN {
/**
* 删除文件夹,需要先删除文件夹里面的内容
* @param dir
*/
public static void deleteFolder(String dir){
File folder=new File(dir);
if(folder.isDirectory()==false){
System.err.println(dir+" is not a folder!");
}else{
String[] files=folder.list();
for(int i=0;i<files.length;i++){
File child=new File(dir+"/"+files[i]);
if(child.isDirectory()){
deleteFolder(dir+"/"+files[i]);
}else{
child.delete();
}
}
folder.delete();
}
}
public static void checkFileFolder(String dir){
File handle=new File(dir);
if(handle.exists()!=false){
if(handle.isDirectory()==true){
String[] files=handle.list();
for(int i=0;i<files.length;i++){
//删除svn文件
if(files[i].equals(".svn")){
System.out.println("svn: "+files[i]);
String fileName=dir+"/"+files[i];
deleteFolder(fileName);
// if(fileSVN.delete()==false)
// System.out.println("delete "+fileName +" failed");
// else
// System.out.println("delete succeed");
}
else{
String fileName=dir+"/"+files[i];
File fileChild=new File(fileName);
if(fileChild.isDirectory()){
System.out.println("folder: "+fileName);
checkFileFolder(fileName);
}else{
System.out.println(fileName);
}
}
}
}
}
return;
}
public static void main(String[] args){
if(args.length!=1){
System.out.println("usage: filterSVN.jar fileFolder");
}
else{
FilterSVN.checkFileFolder(args[0]);
}
}
}