-
Notifications
You must be signed in to change notification settings - Fork 2
/
rename_solution.py
59 lines (46 loc) · 2.05 KB
/
rename_solution.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
import os
import sys
import fileinput
def delete_file(path :str):
if (os.path.exists(path)):
os.remove(path)
def rename_file_and_content(dir :str, extension :str, old_name :str, new_name :str):
if (os.path.exists(dir + old_name + extension)):
os.rename(dir + old_name + extension, dir + new_name + extension) # rename file
if (os.path.exists(dir + new_name + extension)):
f = open(dir + new_name + extension,'r')
filedata = f.read()
f.close()
newdata = filedata.replace(old_name, new_name)
f = open(dir + new_name + extension,'w')
f.write(newdata)
f.close()
def main (new_name : str):
os.chdir(os.path.dirname(os.path.realpath(__file__)))
old_name = None
for file in os.listdir():
if (file.endswith(".sln")):
old_name = file.replace(".sln", "")
if (old_name):
print("Old solution name: " + old_name)
print("Renaming solution to: " + new_name)
rename_file_and_content("", ".sln", old_name, new_name)
rename_file_and_content("Sources\\", ".vcxproj", old_name, new_name)
rename_file_and_content("Sources\\", ".vcxproj.filters", old_name, new_name)
rename_file_and_content("Sources\\", ".rc", old_name, new_name)
rename_file_and_content("Sources\\", ".vcxproj.user", old_name, new_name)
rename_file_and_content("Sources\\", ".vcxproj.orig", old_name, new_name)
rename_file_and_content("Sources\\", ".vcxproj.filters.orig", old_name, new_name)
delete_file("x64\\Release\\" + old_name + ".exe")
delete_file("x64\\Release\\" + old_name + ".pdb")
delete_file("x64\\Debug\\" + old_name + ".exe")
delete_file("x64\\Debug\\" + old_name + ".pdb")
delete_file("Sources\\" + old_name + ".aps")
print("Solution renamed successfully.")
else:
print("Solution file not found")
if __name__ == "__main__":
if (len(sys.argv) > 1 and len(sys.argv[1]) > 0):
main(sys.argv[1])
else:
print("ERROR: Provide argument for new name!")