defsearch(path=".", name=""): for item in os.listdir(path): item_path = os.path.join(path, item) if os.path.isdir(item_path): search(item_path, name) elif os.path.isfile(item_path): if name in item: global result result.append(item_path) print (item_path)
search(path=cwd+'\\Word', name=".docx")
files = result defcombine_all_docx(filename_master,files_list): number_of_sections=len(files_list) master = Document(filename_master) master.add_page_break() # 强制新一页 composer = Composer(master) for i inrange(1, number_of_sections): doc_temp = Document(files_list[i]) doc_temp.add_page_break() # 强制新一页 composer.append(doc_temp) composer.save("合并结果.docx")