Python基础


参考

编译器参考


日志

  • 2022年09月23日12:52:54 初始版本

实用方案

多个MD文档的合并

# 使用说明:
# 1. 将本文件放置到需要合并的MD文件目录中

import os
import time

# 获取当前文件路径
path = os.path.abspath(os.path.dirname(__file__))

fileList = os.listdir(path)

contents = []
for _file in fileList:
    if '.md' not in _file:
        continue
    md_file = os.path.join(path, _file)
    with open(_file, 'r', encoding='utf-8') as file:
        contents.append(file.read() + "\n")

# 新建一个文件
newFileName = time.strftime('%Y-%m-%d %H%M%S', time.localtime()) + '.md'
print(newFileName)
open(newFileName, 'x')

# 写入文件内容
with open(newFileName, 'w', encoding='utf-8') as file:
    file.writelines(contents)

posted on 2022-09-23 12:55  zyjhandsome  阅读(20)  评论(0编辑  收藏  举报