参考:
import re
import glob
#读取整个文件
file = glob.iglob(r'.\src\*.v')
for i in file:
with open(i,'r', encoding='utf-8') as f1:
all_text = f1.read()
new_text = re.sub(r'(\(\*mark_debug \= \"true\"\*\))|(\(\*MARK_DEBUG \= \"TRUE\"\*\))','',all_text)
f1.close()
with open(i,'w', encoding='utf-8') as f2:
f2.write(new_text)
f2.close()
之前的代码,不支持遍历子目录的内容,先更新代码后,可以支持遍历子目录的内容。
import re
import glob
#读取整个文件
file = glob.iglob(r'**\*.v',recursive=True)
for i in file:
with open(i,'r', encoding='utf-8') as f1:
all_text = f1.read()
new_text = re.sub(r'(\(\*mark_debug \= \"true\"\*\))|(\(\*MARK_DEBUG \= \"TRUE\"\*\))','',all_text)
f1.close()
with open(i,'w', encoding='utf-8') as f2:
f2.write(new_text)
f2.close()
REF: