Skip to content

Instantly share code, notes, and snippets.

@chenyahui
Created January 9, 2019 10:26
Show Gist options
  • Select an option

  • Save chenyahui/3954e5d54f5a1c6a65af95f72189147e to your computer and use it in GitHub Desktop.

Select an option

Save chenyahui/3954e5d54f5a1c6a65af95f72189147e to your computer and use it in GitHub Desktop.
统计代码行数
# coding=utf-8
import os
basedir = './corn'
whitelist = ['cpp', 'h']
def get_files_in_dir(basedir):
filelists = []
for parent,dirnames,filenames in os.walk(basedir):
for filename in filenames:
ext = filename.split('.')[-1]
if ext in whitelist:
filelists.append(os.path.join(parent,filename))
return filelists
def countLine(fname):
count = 0
for file_line in open(fname, 'rb').readlines():
count += 1
print(fname + '----' , count)
return count
if __name__ == '__main__' :
file_lists = get_files_in_dir(basedir)
totalline = 0
for filelist in file_lists:
totalline = totalline + countLine(filelist)
print('total lines:',totalline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment