-
Notifications
You must be signed in to change notification settings - Fork 25
/
pg.py
77 lines (42 loc) · 1.64 KB
/
pg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys
import os
import shutil
newtemplate = "tes1t"
def ReplaceString(strData,old,new):
#strData = ""
strData = strData.replace(old,new)
return strData
def ReplaceFile(CurPath,NewPath,CurFileName,old,new):
CurFileName = str(CurFileName)
NewFileName = ReplaceString(CurFileName,old,new)
CurFilePath = os.path.join(CurPath,CurFileName)
NewFilePath = os.path.join(NewPath,NewFileName)
CurFP = open(CurFilePath,"r")
NewFP = open(NewFilePath,"w")
CurData = CurFP.read()
NewData = CurData.replace(old,new)
NewFP.write(NewData)
CurFP.close()
NewFP.close()
def RecurseDir(CurRoot,NewRoot,old,new):
CurFileItems = os.listdir(CurRoot)
for item in CurFileItems:
itemPath = os.path.join(CurRoot,item)
if os.path.isfile(itemPath):
ReplaceFile(CurRoot,NewRoot,item,old,new)
elif os.path.isdir(itemPath):
newitem = ReplaceString(item,old,new)
NewSubPath = os.path.join(NewRoot,newitem)
if not os.path.isdir(NewSubPath):
os.mkdir(NewSubPath)
CurSubPath = os.path.join(CurRoot,item)
RecurseDir(CurSubPath,NewSubPath,old,new)
if __name__ == "__main__":
newtemplate = raw_input("please input new ActionName:")
CurRoot = r".\template"
"Trans" + newtemplate + "Action"
NewRoot = ".\\" + "Trans" + newtemplate + "Action"
if not os.path.isdir(NewRoot):
os.mkdir(NewRoot)
RecurseDir(CurRoot,NewRoot,"9999",newtemplate)
os.system("pause")