时间:2021-07-01 10:21:17 帮助过:54人阅读
代码如下:
#-*- coding:utf-8 -*-
#!/usr/bin/python
import os
#定义程序根目录
rootpath='D:\\wamp\\www\\erp\\app'
def m_replace(path):
for item in os.listdir(path):
nowpath=os.path.join(path,item)
if os.path.isdir(nowpath):
m_replace(nowpath)
else:
if nowpath.find('.php')>0:
f=open(nowpath,'r+')
content=f.read().replace('& new ','new ')
open(nowpath,'w').write(str(content))
f.close()
if __name__=="__main__":
m_replace(rootpath)