很多小项目,内容基本一致,细微差距,又能封装,修改工程比较麻烦 正常的操作 修改iOS工程名
发现CocoaPods的Pod Lib Create 就是下载模板然后替换内容 觉的可以试试直接替换
使用了python,其它语言应该差不多
import os
def deal_file_content(file_path, old_name, new_name): # 处理替换的文件
try:
if file_path.endswith('.DS_Store'):
return
f = open(file_path, 'r+', )
content = f.readlines()
f.seek(0, 0)
for line in content:
line_new = line.replace(old_name, new_name)
f.write(line_new)
f.close()
except Exception as err:
print(file_path)
print(err)
# 遍历指定目录下所有子目录,并且修改
def each_file(dir_path, old_name, new_name):
path_dir = os.listdir(dir_path)
for allDir in path_dir:
# 自己选择忽略几个文件夹 处理的不好 我自己够用了 你们看着改
if allDir == 'Assets.xcassets' or allDir == 'base_project' or allDir == 'Base.lproj':
continue
child = os.path.join('%s/%s' % (dir_path, allDir))
if allDir.__contains__(old_name):
if os.path.isdir(child): # 是文件夹
new_path = os.path.join('%s/%s' % (dir_path, allDir.replace(old_name, new_name)))
os.rename(child, new_path)
child = new_path
if os.path.isdir(child):
each_file(child, old_name, new_name)
else:
deal_file_content(child, old_name, new_name)
执行
each_file('../workspace/xxx', old_name="xxx", new_name="abc")
可能会略微简单点…
操作前记得备份好代码…