1 ImportOs#import file Operation module2 ImportRe#Import the regular module3 ImportWin32com#Import the Word action module4 5 #ready to open Word6 fromWin32com.clientImportdispatch,constants7W = Win32com.client.Dispatch ('Word.Application')8W.visible =09W.displayalerts =0Ten One #get the full path of the text A #.. \1_ a unit \1_ "Yi reading" \1_ preview \1_ Sound and picture text - forRoot, Dirnames, filenamesinchOs.walk (R'C:\Users\jack\Desktop\test\3_ Chinese language edition seven-year book'): - ##字符串前面加r之后, the \d in the regular does not change, ' \ ' becomes ' \ \ ', the beginning is ' ^$ ', match all is '. ' the ## if Re.match (R '. *\\\d+_\w+\\\d+_.+\\1_ Preview \\1_ Sound Draw text $ ', Dirpath): - ## Print (Dirpath) - ## Else: - ## print (' not found ') + forFileNameinchFilenames: - ifRe.match (R'text. rtf', filename): +Classrtf =Os.path.join (root,filename) Adoc = W.documents.open (FileName =classrtf) at W.activedocument.select () - w.selection.clearformatting () - Print("processed:"+classrtf) - Doc. Close () - W.quit - Print("Finish the deal! ")
Python Changes the text