修改所有pw.sh 并把里面的字符串“dw”都换成“pw”

import os

link = './'


def alter(file,old_str,new_str):
  file_data = ""
  with open(file, "r" ) 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") as f:
    f.write(file_data)



for i in os.listdir(link):
    if "pw" in i and i.endswith(".sh"):
       print(i)
       alter(i,"dw","pw")

 

posted on 2020-05-05 12:18  cdekelon  阅读(55)  评论(0)    收藏  举报

导航