python 在头文件添加 #include \"stdafx.h\"\r\n

import os
import shutil
#-*- coding:cp936 -*-
import codecs
from sys import argv

def replace_all_files(path):
cnt = 0
for root, dirs, files in os.walk(path):
for name in files:
if name.endswith(".cpp"):
f = codecs.open(os.path.join(root, name), "rb+")
text = f.read()
text1 = text
if text.find("\"stdafx.h\"")<0:
key = "#include \"stdafx.h\"\r\n"
if text[:3]==codecs.BOM_UTF8:
text1 = "%s%s%s" % (codecs.BOM_UTF8, key, text[3:])
else:
text1 = "%s%s" % (key, text)
f.seek(0)
f.truncate()
f.write(text1)
cnt = cnt+1
print "[%d] relpace File: " %cnt + os.path.join(root, name)
f.close()

if __name__ == "__main__":
try:
replace_all_files(argv[1])
except Exception, e:
print e.message

上一篇:Spring Boot 配置加载顺序详解


下一篇:c++中的#include "stdafx.h"