标签:
1 import os #导入文件操作模块 2 import re #导入正则模块 3 import win32com #导入word操作模块 4 5 #准备打开word 6 from win32com.client import Dispatch,constants 7 w = win32com.client.Dispatch(‘Word.Application‘) 8 w.Visible = 0 9 w.DisplayAlerts = 0 10 11 #获取课文全路径 12 #..\1_一单元\1_《忆读书》\1_预习\1_音画课文 13 for root, dirnames, filenames in os.walk(r‘C:\Users\jack\Desktop\test\3_语文语文版七年级上册‘): 14 ##字符串前面加r之后,正则里的\d等都不用变,‘\‘变成‘\\‘即可,开头末尾是‘^$‘,匹配全部是‘.*‘ 15 ## if re.match(r‘.*\\\d+_\w+\\\d+_.+\\1_预习\\1_音画课文$‘,dirpath): 16 ## print(dirpath) 17 ## else: 18 ## print(‘未找到‘) 19 for filename in filenames: 20 if re.match(r‘课文.rtf‘,filename): 21 classRTF = os.path.join(root,filename) 22 doc = w.Documents.Open(FileName = classRTF) 23 w.ActiveDocument.Select() 24 w.Selection.ClearFormatting() 25 print("已处理:" + classRTF) 26 doc.Close() 27 w.Quit 28 print("处理完毕!")
标签:
原文地址:http://www.cnblogs.com/Jacklovely/p/5747868.html