#_*_coding:utf_8_
import os
import glob
def countFileLines(filename):
count = 0
try:
handle = open(filename, 'r')
for eachline in handle:
count += 1
except IOError, e:
print 'file open error', e
print 'file:' , filename, 'has %d lines' % count
return count
def folderCodeLines(folderpath):
count = 0
filetype = ['*.py', '*.c', '*.cpp'] #指定需要统计的文件类型的列表
for type in filetype:
print type
filepath = str(folderpath) + '/' + str(type)
for file in glob.glob(filepath):
count += countFileLines(file)
print count
return count
folderCodeLines('D:/study/practice/algorithm')
统计文件夹内指定类型文件的代码行数(二)
最新推荐文章于 2020-04-29 11:50:35 发布