我的Python自学之路测试员的那点事

批量给md文件写入内容

2021-09-30  本文已影响0人  望月成三人
import os

path = r"D:\book\user-2231755-1632815565\python"

for root, dirs, files in os.walk(path, topdown=False):
    for name in files:
        _path = os.path.join(root, name)
        _name = name[:len(name)-3]
        with open(_path, "r+", encoding="utf-8") as f:
            old = f.read()
            f.seek(0)
            f.write("---\n")
            f.write("title: %s\n" %_name)
            f.write("date: 2021-09-29 17:13:35\n")
            f.write("categories: python\n")
            f.write("---\n")
上一篇下一篇

猜你喜欢

热点阅读