-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrepostats.py
54 lines (43 loc) · 1.7 KB
/
repostats.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os, time
fileCount = 0
folderCount = 0
lineCount = 0
wordCount = 0
charCount = 0
meaningfulCharCount = 0
alphanumCharCount = 0
def march(directory):
global fileCount, folderCount, lineCount, wordCount, charCount, meaningfulCharCount, alphanumCharCount
for current_dir, sub_dirs, files in os.walk(directory):
for name in files:
if name.lower().endswith(".java"):
fileCount += 1
with open(os.path.join(current_dir, name), encoding="utf8") as file:
content = file.read().split("\n")
lineCount += len(content)
for line in content:
for word in line.split():
for char in word:
if char.isalnum():
wordCount += 1
break
for char in word.strip():
meaningfulCharCount += 1
if char.isalnum():
alphanumCharCount += 1
charCount += len(line)
for directory in sub_dirs:
folderCount += 1
march(directory)
if __name__ == "__main__":
startTime = time.time_ns()
march(os.getcwd())
time = time.time_ns() - startTime
print(f"Files: {fileCount}")
print(f"Folders: {folderCount}")
print(f"Line Count: {lineCount}")
print(f"Word Count: {wordCount}")
print(f"Char Count: {charCount}")
print(f"Char NO SPACE Count: {meaningfulCharCount}")
print(f"Char NON SPECIAL Count: {alphanumCharCount}")
print(f"Took {time}ns or {time / 1000000}ms to run.")