有时候直接改了package,但是里面的R文件引包的package没有变化
def modify_packagename(path):
# 获取所有子文件
list1 = os.listdir(path)
for item in list1:
# print(item)
cpath = path + "\\"+ item
if os.path.isfile(cpath):
print(cpath)
alter(cpath, "原applicationId", "新applicationId")
else:
modify_packagename(cpath)
def alter(file,old_str,new_str):
"""
替换文件中的字符串
:param file:文件名
:param old_str:就字符串
:param new_str:新字符串
:return:
"""
file_data = ""
with open(file, "r", encoding="utf-8") as f:
for line in f:
if old_str in line:
line = line.replace(old_str,new_str)
file_data += line
with open(file,"w",encoding="utf-8") as f:
f.write(file_data)
if __name__ == "__main__":
#modify_name()
path = '包名根目录'
#modify_packagename(path)