Skip to content

Instantly share code, notes, and snippets.

@vikingmute
Created June 4, 2014 09:39
Show Gist options
  • Save vikingmute/058e6f683f1b7b51e972 to your computer and use it in GitHub Desktop.
Save vikingmute/058e6f683f1b7b51e972 to your computer and use it in GitHub Desktop.
get line numbers
import os,sys
dirname = sys.argv[1]
totalCount = 0;
cDir = os.getcwd()
#allowd file extsions, .js, .css ...
extDir = ['.js', '.less', '.tpl', '.html']
#dir avoided to be checked
avoidDir = ['index/tpl', 'index/js']
for root, dirs, files in os.walk(dirname):
suitDir = [ar for ar in avoidDir if root.find(ar) != -1]
if len(suitDir) > 0 :
continue
for f in files:
filename, fileExt = os.path.splitext(f)
if fileExt in extDir:
os.chdir(root)
ff = open(f, 'r')
lines = len(ff.readlines())
totalCount += lines
os.chdir(cDir)
print 'filename: ' + f + ' lines:' + str(lines) + ' total:' + str(totalCount) + '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment