import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
public class CleanSVN {
public static void main(String[] args){
String testurlString="args[0]";
System.out.println(clean(testurlString));
}
public static String clean(String url){
File files=new File(url);
if(!files.exists())return "no such directory";
String str[]=files.list();
for(int i=0;i<str.length;i++){
String cDIR=url+"\\"+str[i];
File cstr=new File(cDIR);
if(cstr.isDirectory()){
if(str[i].endsWith(".svn")){
deletedoc(cstr);
}else{
clean(cDIR);
}
}
}
return "all '.svn' is cleaned";
}
public static void deletedoc(File cstr){
String dir=cstr.getAbsolutePath();
String[] dirs=cstr.list();
for(int i=0;i<dirs.length;i++){
File sFile=new File(dir+"\\"+dirs[i]);
if(sFile.isDirectory()){
deletedoc(sFile);
}else{
System.out.println(dir+"\\"+dirs[i]+"is deleting ****************");
sFile.delete();
}
}
cstr.delete();
}
}
以上这段代码 清除了 SVN checkout出来的工程中的标记 工程地址由命令行参数 给出
下面是 python 的写法 主要学会os模块
#!/usr/bin/env python
#-*-coding:utf-8-*-
import sys,os,stat
def walk(path):
for item in os.listdir(path):
subpath=os.path.join(path, item)
mode=os.stat(subpath)[stat.ST_MODE]
if stat.S_ISDIR(mode):
if item==".svn":
print "Cleaning %s ..." %subpath
print "%d deleted" %purge(subpath)
else:
walk(subpath)
def purge(path):
count=0
for item in os.listdir(path):
subpath=os.path.join(path, item)
mode=os.stat(subpath)[stat.ST_MODE]
if stat.S_ISDIR(mode):
count+=purge(subpath)
else:
os.chmod(subpath, stat.S_IREAD|stat.S_IWRITE)
os.unlink(subpath)
count+=1
os.rmdir(path)
count+=1
return count
if __name__== '__main__':
if len(sys.argv)!=2:
print "Usage: python SVNClean.py path"
sys.exit(1)
walk(sys.argv[1])