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   zyjhandsome  阅读(21)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
历史上的今天:
2018-09-23 Java 输入/输出——File类
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

统计

点击右上角即可分享
微信分享提示