背景:
①小程序目前没有全局替换;只有全局搜索
②需要将界面中的 xxx改为yyy;
叄:开发已经将近完成 近百个文件
所以
考虑到了python:
https://blog.youkuaiyun.com/shenxian1021/article/details/81873845 原地址
原博主写的是相对路径 所以改成了全路径 并且遍历子目录 完成全局替换;
代码:
# coding=utf-8
import os
import io
def alter(file, old_str, new_str):
"""
替换文件中的字符串
:param file:文件全地址
:param old_str:旧字符串
:param new_str:新字符串
:return:
"""
file_data = ""
# print('currentFile-->',file)
with io.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 io.open(