I have a folder of many word document files ending with .doc and .docx.
This code is working only for .docx I want this for .doc also
import docx
import os
charCounts = {}
directory = os.fsencode('.')
for file in os.listdir(directory):
filename = os.fsdecode(file)
if filename.endswith(".docx"):
#filename = os.path.join(directory, filename)
doc = docx.Document(filename)
chars = sum(len(p.text) for p in doc.paragraphs)
charCounts[filename] = chars / 65
# uses openpyxl package
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.cell(row=1, column=2, value='File Name')
ws.cell(row=1, column=4, value='chars/65')
for i, x in enumerate(charCounts):
ws.cell(row=i + 3, column=2, value=x)
ws.cell(row=i + 3, column=4, value=charCounts[x])
ws.cell(row=len(charCounts) + 3, column=4, value=sum(charCounts.values()))
path = './charCounts.xlsx'
wb.save(path)
Images:-
I want them to happen like these:
Notice two things here.
File names in excel sheet have been arranged number-wise.
Second thing is in excel sheet, the file extensions have been removed. I want it Like that.

