-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchange.py
More file actions
24 lines (21 loc) · 796 Bytes
/
change.py
File metadata and controls
24 lines (21 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'''
批量修改目录下文件的需要改动的内容
'''
import os
def getAllfileAndDirPath(sourcePath):
if not os.path.exists(sourcePath):
return
listName = os.listdir(sourcePath)
for name in listName:
absPath = os.path.join(sourcePath,name)
if os.path.isfile(absPath):
if absPath.find('.') != -1 and absPath[absPath.find('.') :] == ".php":
with open(absPath,'rb+') as f:
t = f.read().decode('utf8')
t = t.replace("shanghai.com.cn","onmycard.com.cn")
f.seek(0,0)
f.write(t.encode('utf8'))
print("修改%s完成" % absPath)
if os.path.isdir(absPath):
getAllfileAndDirPath(absPath)
getAllfileAndDirPath(r'test')