-
Notifications
You must be signed in to change notification settings - Fork 4
/
fss.py
executable file
·74 lines (63 loc) · 2.15 KB
/
fss.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File System Statistics
# Noah Kim
# Import
import os
import collections
# Main
counter = \
{
"paths": [],
"files": 0,
"folders": 0,
"types": collections.Counter(),
"readable": 0,
"unreadable": 0,
"lines": 0,
"chars": 0,
"size": 0
}
def recurse(counter, path=os.getcwd()):
for item in os.listdir(path):
subpath = os.path.join(path, item)
counter["paths"].append(subpath)
if os.path.isfile(subpath):
if not subpath.endswith(".gitignore"):
counter["files"] += 1
counter["types"][os.path.splitext(subpath)[1]] += 1
try:
file = open(subpath)
contents = file.read()
counter["readable"] += 1
except:
counter["unreadable"] += 1
else:
counter["lines"] += contents.count("\n")
counter["chars"] += len(contents)
finally:
file.close()
counter["size"] += os.path.getsize(subpath)
else:
if not subpath.endswith(".git"):
counter["folders"] += 1
counter["size"] += os.path.getsize(subpath)
recurse(counter, subpath)
if __name__ == "__main__":
recurse(counter)
print("Files".ljust(15, "."), counter["files"], sep="")
print("Folders".ljust(15, "."), counter["folders"], sep="")
print("Total".ljust(15, "."), counter["files"] + counter["folders"], sep="")
print()
print("Types")
for type, count in sorted(counter["types"].items(), key=lambda item: item[1], reverse=True):
print((" %s" % (type if type != "" else "none")).ljust(15, "."),
count, sep="")
print()
print("Readable".ljust(15, "."), counter["readable"], sep="")
print("Unreadable".ljust(15, "."), counter["unreadable"], sep="")
print()
print("Lines".ljust(15, "."), counter["lines"], sep="")
print("Characters".ljust(15, "."), counter["chars"], sep="")
print()
print("Size".ljust(15, "."), round(counter["size"] / 1.049e+6, 2), "MB",
sep="")
input()