Created
January 9, 2019 10:26
-
-
Save chenyahui/3954e5d54f5a1c6a65af95f72189147e to your computer and use it in GitHub Desktop.
统计代码行数
This file contains hidden or 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 | |
| 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