|
- from docx import Document
- import os
- path = ".\\小论文"
- for parent,dirnames,filenames in os.walk(path):
- for filename in filenames: #输出文件信息
- fullname = path+"\"+ filename;
- print(fullname)
- try:
- doc = Document(fullname)
- paragraphs = doc.sections[0].header.paragraphs
- section = doc.sections[0]
- header = section.header
- header.paragraphs[0].text = filename
- doc.save("M"+filename)
- except:
- print("失败")
复制代码 |
|