Python实现计算文件夹下.h和.cpp文件的总行数
更新时间:2015年04月23日 09:43:36 投稿:junjie
这篇文章主要介绍了Python实现计算文件夹下.h和.cpp文件的总行数,本文直接给出实现代码,需要的朋友可以参考下
平时自己写了很多代码,但从没好好计算总共写了多少行,面试时被问起来,就傻了。。。闲来无事,写个python程序来统计下
import os
################################################################################
def calcLine(baseDir):
lineCount = 0
try:
for fileName in os.listdir(baseDir):
fullPath = baseDir + fileName
if os.path.isdir(fullPath):
lineCount += calcLine(fullPath + '\\') #递归读取所有文件
if os.path.splitext(fullPath)[1] in (".h", ".cpp"):
file = open(fullPath)
for eachLine in file.readline():
lineCount += 1
file.close()
except Exception as e:
print(e)
return lineCount
################################################################################
if __name__ == "__main__":
baseDir = "K:\\C++\\MFC\\BubbleDragon\\"
lineCount = calcLine(baseDir)
print(lineCount)
相关文章
浅谈Python3中strip()、lstrip()、rstrip()用法详解
这篇文章主要介绍了浅谈Python3中strip()、lstrip()、rstrip()用法详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2019-04-04
django请求返回不同的类型图片json,xml,html的实例
今天小编就为大家分享一篇django请求返回不同的类型图片json,xml,html的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-05-05


最新评论