python一个目录下以及子目录下所有文件里,内容每一行如果是空格若干+字符串开始"printf"+其他字符,这一行删除.用python如何写
一个目录下以及子目录下所有文件里,内容每一行如果是空格若干&&字符串开始"printf"&&其他字符,这一行删除.用python如何写
目的就是删除项目代码里的所有调试代码,清理干净.
例如
int a = 5; printf("%d",a); //打印a的值
#========================================================# author:ago # 2012/09/20 10:08:42 #========================================================import osDIR = 'dir_name'for root,dirs,files in os.walk(DIR): for file in files: print file f = open(DIR+'/'+file) data = f.read() f.close() alist = data.split('\n') string = '' for i in alist: print i if 'printf' not in i: string += i + '\r\n' #print string f = open(DIR+'/'+file , 'w') f.write(string) f.close()
[解决办法]