几句话就可以写好。
import os
onedir="."
keyword="xxx"
appendtext=""
for r,ds,fs in os.walk(onedir):
for f in fs:
fn=os.path.join(r,f)
if open(fn,"rb").read().find(keyword)>=0:
open(fn,"ab).write(appendtext)
def walkXXX(arg, path, names):
for name in names:
searchXXX(name)
def searchXXX(filename):
f = open(filename, "r+")
f.write(f.read().replace("XXX", "XXX几行同样的内容"))
f.close()
os.path.walk("目录", walkXXX, None)
能不能举个例子啊,不知道你在问什么