def classify_count(prj, res, et, ef):
if os.path.isdir(prj): # ??????????
files = os.listdir(prj)
for file in files:
if file.find('.') == 0: continue # ??????
loc = file.rfind('.') # ????????
fname = file[:(loc if loc != -1 else len(file))] # ???
ftype = file[(loc + 1 if loc != -1 else len(file)):] # ????
curp = prj + '/' + file # ?????????
if fname in origin_folder or ftype in origin_type or ftype in et or fname in ef: continue # ??????????
if os.path.isdir(curp): classify_count(curp, res, et, ef) # ???????????????
elif imghdr.what(curp): continue # ??????????????
else:
try:
with open(curp, 'r') as f:
words = re.sub('\\s+(/\\*([.\\s\\S]*?)\\*/)|(//.*)', '', f.read()) # ????????????????
codelines = [line for line in words.split('\n') if len(line.strip()) > 0] # ???????????????????
if not ftype in res.keys(): res[ftype] = 0 # ????
res[ftype] += len(codelines)
if not file_count_key in res.keys() : res[file_count_key] = 1
res[file_count_key] += 1
print('%5d %s' % (len(codelines), curp))
except Exception as e: print(curp, e)
评论列表
文章目录