有语胜无语import osdef test(path, ext): for f_or_d in [path + os.sep + s for s in os.listdir(path) if (os.path.splitext(s)[1] in ext or os.path.isdir(path + os.sep + s))]: if os.path.isdir(f_or_d): test(f_or_d, ext) else: print 'modify file:' + f_or_d f = open(f_or_d, "r+") data = f.read() data = data.replace("abcd", "")
用JAVA打开文件,替换之后再保存~~~~╭═══════════════════╮
║ 免费的源码、工具网站,欢迎大家访问!║
║ http://www.j2soft.cn/ ║
╰═══════════════════╯
写个shell吧#/bin/bashfor i in *.htm; do
sed -e 's/abcd//g' $i
done
for f_or_d in [path + os.sep + s for s in os.listdir(path)
if (os.path.splitext(s)[1] in ext or os.path.isdir(path + os.sep + s))]:
if os.path.isdir(f_or_d):
test(f_or_d, ext)
else:
print 'modify file:' + f_or_d f = open(f_or_d, "r+")
data = f.read()
data = data.replace("abcd", "")
f.seek(0)
f.truncate()
f.write(data)
f.close()if __name__ == "__main__":
test("d:\\DownLoads", ['.htm'])