forked from jkperin/optical-comm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_stats.py
42 lines (33 loc) · 872 Bytes
/
code_stats.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
import os
from os import walk
local_path = "C:/Users/Joe/Dropbox/research/codes";
def file_len(fname):
with open(fname, 'rb') as f:
for i, l in enumerate(f):
pass
return i + 1
files = [];
for (dirpath, dirnames, filenames) in walk(local_path):
for f in filenames:
if ".git\\" in dirpath:
continue;
else:
files.append(dirpath+"/"+f);
extensions = {};
for f in files:
try:
p = f.index('.');
except ValueError:
continue;
try:
extension = f[p:];
lines = file_len(f);
if extension in extensions:
extensions[extension] += lines;
else:
extensions[extension] = lines;
except Exception:
print("Could not open file", f)
print("Extensions")
for e in extensions:
print(e, extensions[e]);