1
0
mirror of https://github.com/osmarks/random-stuff synced 2024-11-08 13:39:53 +00:00
random-stuff/count_words_in_directory.py

14 lines
461 B
Python
Raw Normal View History

2023-06-19 13:09:54 +00:00
import os, sys, string
count = 0
words = 0
characters = 0
for dirpath, dirnames, filenames in os.walk(sys.argv[1]):
for filename in filenames:
with open(os.path.join(dirpath, filename)) as f:
content = f.read()
characters += len([c for c in content if c in string.ascii_letters])
words += len([thing for thing in content.split() if thing.strip()])
count += 1
print(words / count, characters / count)