Last active
August 29, 2015 14:02
-
-
Save xiaotangyuan/c24707edfe9138b59f36 to your computer and use it in GitHub Desktop.
计算当前文件夹下文件行数(代码量)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import os | |
def countlines(thefile): | |
lines=0 | |
with open(thefile) as f: | |
for line in f.readlines(): | |
if len(line)>1: | |
# print line | |
lines=lines+1 | |
return lines | |
#递归找出所有文件 | |
def findfile(mulu): | |
files=[] | |
wj=os.listdir(mulu) | |
for f in wj: | |
f=os.path.join(mulu,f) | |
if os.path.isfile(f): | |
files.append(f) | |
# print f | |
else: | |
files=files+findfile(f) | |
return files | |
def cleanfiles(files): | |
newfiles=[] | |
nofile=[__file__,'.pyc','.jpg','png','jquery','bootstrap','redactor','glyphicons','fontawesome','\\static\\admin','oss','warn.log'] | |
for f in files: | |
getit=True | |
for nf in nofile: | |
if nf in f: | |
getit=False | |
break | |
if getit: | |
newfiles.append(f) | |
return newfiles | |
mulu=os.path.dirname(__file__) | |
# print findfile(mulu) | |
files=findfile(mulu) | |
files=cleanfiles(files) | |
print 'allfiles:'+str(len(files)) | |
alllines=0 | |
output=open('countlines.txt','w') | |
for f in range(len(files)): | |
lines=countlines(files[f]) | |
alllines=alllines+lines | |
print >>output,f,files[f],str(lines) | |
print >>output,'allfiles:'+str(len(files)) | |
print >>output,'alllines:'+str(alllines) | |
print >>output,alllines/45 | |
output.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment