Puteţi vizualiza întregul cod aici: https://pastebin.com/4yL0irEp
Instalaţi Python.
#------------------------------------------------------------------------------- # Name: Convert Doc and DocX to PDF # Purpose: # # Author: Fantanaru Neculai # # Created: 18/03/2022 # Copyright: (c) Fantanaru Neculai 2022 #------------------------------------------------------------------------------- # pip install pywin32 # pip install docx2txt import docx2txt from win32com import client import os files_from_folder = r"c:\\doc" directory = os.fsencode(files_from_folder) amount = 1 word = client.DispatchEx("Word.Application") word.Visible = True for file in os.listdir(directory): filename = os.fsdecode(file) print(filename) if filename.endswith('docx'): text = docx2txt.process(os.path.join(files_from_folder, filename)) print(f'{filename} transfered ({amount})') amount += 1 new_filename = filename.split('.')[0] + '.txt' try: with open(os.path.join(files_from_folder + r'\txt_files', new_filename), 'w', encoding='utf-8') as t: t.write(text) except: os.mkdir(files_from_folder + r'\txt_files') with open(os.path.join(files_from_folder + r'\txt_files', new_filename), 'w', encoding='utf-8') as t: t.write(text) elif filename.endswith('doc'): doc = word.Documents.Open(os.path.join(files_from_folder, filename)) text = doc.Range().Text doc.Close() print(f'{filename} transfered ({amount})') amount += 1 new_filename = filename.split('.')[0] + '.txt' try: with open(os.path.join(files_from_folder + r'\txt_files', new_filename), 'w', encoding='utf-8') as t: t.write(text) except: os.mkdir(files_from_folder + r'\txt_files') with open(os.path.join(files_from_folder + r'\txt_files', new_filename), 'w', encoding='utf-8') as t: t.write(text) word.Quit()
That's all folks.
If you like my code, then make me a favor: translate your website into Romanian, "ro".
Also, you can see other Python Codes: VERSION 2 of this code. Or Version 3 OR Version 4 OR Version 5
Puteţi vizualiza şi versiunea de cod în PowerShell or VERSION 2 or VERSION 3