背景需求:
前期制作了单题文件夹

每个二级文件夹里都有1-2份docx文件


每个二级文件夹里都有1-2份docx文件------有5分钟字样那份docx不需要



如何批量提取 7个二级文件夹里不含"5分钟"字样的docx?并将7个docx合并成PDF?

代码展示:

python
'''
读取一级文件夹中的所有二级文件夹,二级文件夹里面的所有docx复制到一级文件夹的二级文件夹"整理"文件夹
作者:阿夏(AI对话大师)
时间:2024年3月3日
'''
import os,time
import shutil
print('-----1、复制d每个二个文件夹下的(没有5分钟字样的docx文件到二级文件夹里-------')
# 一级文件夹路径
folder_path = r'D:\04三级操作题'
# 目标文件夹路径
new_path = folder_path+r'\整理'
# 获取一级文件夹中的所有二级文件夹(包括整理文件夹)
subfolders = [f.path for f in os.scandir(folder_path) if f.is_dir()]
# 遍历二级文件夹并复制docx文件到目标文件夹
for subfolder in subfolders:
if subfolders=='整理': # 排除"整理"文件夹
pass
else:
docx_files = [f for f in os.listdir(subfolder) if f.endswith('.docx')]
for file in docx_files:
source_file = os.path.join(subfolder, file)
destination_file = os.path.join(new_path, file)
if source_file == destination_file:# 如果复制文件相同,就跳过
continue
if '5分钟' in file:
# # 不要有5分钟文件名的docx
pass
else:
shutil.copy2(source_file, destination_file)
# 19份docx合并成1个pdf



PDF一页一套题(因为前期设置docx,让每个docx里面的文字说明都在一页内)

存在问题:多个docx合并一个PDF后,没有页码,打印后容易散乱。
