python实现把doc文件批量转化为docx
import os
from win32com import client as wcdef doSaveAas(doc_path,docx_path):word = wc.Dispatch('Word.Application')doc = word.Documents.Open(doc_path) doc.SaveAs(docx_path, 12, False, "", True, "", False,False, False, False) doc.Close()word.Quit()def all_doc_files_recursive(folder_path):if not os.path.exists(folder_path):print(f"错误:文件夹 '{folder_path}' 不存在。")returnfor root, dirs, files in os.walk(folder_path):for filename in files:if filename.endswith('.doc'):doc_file_path = os.path.join(root, filename)docx_path=os.path.join(root, filename[:-4])+'.docx'try:if not os.path.exists(docx_path):doSaveAas(doc_file_path,docx_path)print(f"将 '{filename}' 转化为了docx格式'")except:print(f"文件 '{filename}' 转化失败'")
folder_path=r'D:\path'
all_doc_files_recursive(folder_path)