废话不多说,直接贴脚本
需要安装 docx 插件!!!需要安装 docx 插件!!!需要安装 docx 插件!!!
# -*- coding: utf-8 -*-
import os
import docx
def listdir(path, list_name): #传入存储的list
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isdir(file_path):
listdir(file_path, list_name)
else:
if "static" not in file_path and ".ico" not in file_path and ".iml" not in file_path and ".git" not in file_path and "mvnw" not in file_path and "i18n" not in file_path and "OpenDevice." not in file_path and "images" not in file_path and ".gitignore" not in file_path and ".mvn" not in file_path and "exceltemplates" not in file_path and ".xls" not in file_path and "META-INF" not in file_path:
list_name.append(file_path)
list_name = list()
listdir("D:\workspaces\wms-bed", list_name)
print(list_name)
document = docx.Document()
for fileName in list_name:
head = fileName.replace("D:\workspaces\wms-bed\\", "")
document.add_heading(head, 3) #直接添加标题
print(fileName)
with open(fileName, encoding='utf-8') as file_obj:
content = file_obj.read()
document.add_paragraph(content)
document.save("D:/test1.docx") # 保存文档