合并小说(文件)成为一个文件
下载的小说经常是分章节下载的,需要合并到一个文本文档中方便阅读
代码如下
import os
path = r"D:\Users\Administrator\Desktop\xx小说"
path_save = r"D:\Users\Administrator\Desktop\合并小说.txt"
path_list = os.listdir(path) # 获取路径下文件名称,放入列表中(之后可切片按需要排序)
with open(path_save, "a", encoding="utf-8") as file:
for lst in path_list:
with open(path + "\\" + lst, mode="r", encoding='utf-8') as file2:
file.write(file2.read())