python递归统计文件夹下pdf文件的数量
import os
from docx import Documentdef count_all_pages(root_dir):total_pages = 0# 遍历文件夹for dirpath, dirnames, filenames in os.walk(root_dir):for filename in filenames:# if filename.endswith('.docx') or filename.endswith('.doc'):# total_pages+=1if filename.endswith('.pdf'):total_pages+=1return total_pages# 要遍历的文件夹路径
folder_path = r'path'# 调用函数计算页数总和
total_pages = count_all_pages(folder_path)
print(f'所有文档数为: {total_pages}')