-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountWords.py
29 lines (21 loc) · 872 Bytes
/
CountWords.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
Total = 0
Files = os.listdir(os.getcwd()+"/Text")
for File in Files:
if (File[-4:] == ".tex" and File[0:4] == "Chap"):
CommandInText = "texcount ./Text/"+File+" | grep \"Words in text\""
ResultInText = os.popen(CommandInText).read()
WordsInText = ((ResultInText.split(":"))[1]).rstrip()
CommandInCaps = "texcount ./Text/"+File+" | grep \"Words outside text (captions, etc.)\""
ResultInCaps = os.popen(CommandInCaps).read()
WordsInCaps = ((ResultInCaps.split(":"))[1]).rstrip()
String = File+"\t\t"
if (len(File)<16):
String += "\t"
if (len(File)<24):
String += "\t"
String += str(int(WordsInText)+int(WordsInCaps))
Total += int(WordsInText)+int(WordsInCaps)
print(String)
print("-------------")
print("Total:"+str(Total))