#读取docx中的文本代码示例
import docx
from win32com import client as wc
import re
import os
import os.path
def getListFiles(path):
ret = []
for root, dirs, files in os.walk(path):
for filespath in files:
if filespath.endswith(".doc"):
ret.append(os.path.join(root,filespath))
return ret
def doSaveAas(ret):
word = wc.Dispatch('Word.Application')
for i in ret:
l = i.split('\\')[-1]
b = l.split('.')[0]
print(b)
doc = word.Documents.Open(i) # 目标路径下的文件
doc.SaveAs(r'C:\Users\Administrator\Desktop\国网辽宁电力\新建文件夹'+'\\'+b+'.docx', 12, False, "", True, "", False, False, False, False) # 转化后路径下的文件
doc.Close()
word.Quit()
ret = getListFiles(r"C:\Users\Administrator\Desktop\国网辽宁电力\电子版知识库20171120版本(大部分知识内容请在省中心文件夹查看)")
doSaveAas(ret)