i have been trying to use python and the win32com client to save multiple files from .doc to .docx (so i can then edit them with the python docx program) I run the below code and get a "finished with no errors and an exit code of 0" in pycharm. This is my first foray into Python.
After i run it i get 0 errors but the documents are still all .doc
from glob import glob
import re
import os
import win32com.client as win32
from win32com.client import constants
paths = glob('C:\test\*.doc', recursive=True)
def save_as_docx(path):
word = win32.gencache.EnsureDispatch('Word.Application')
doc = word.Documents.Open(path)
doc.Activate ()
new_file_abs = os.path.abspath(path)
new_file_abs = re.sub(r'\.\w+$', '.docx', new_file_abs)
word.ActiveDocument.SaveAs(
new_file_abs, FileFormat=constants.wdFormatXMLDocument
)
doc.Close(False)
for path in paths:
save_as_docx(path)
After this i get
"Process finished with exit code 0" And all of the files are still .doc in the C:\test folder.