Python实现计算文件夹下.h和.cpp文件的总行数
时间:2020-10-25 14:39:12|栏目:Python代码|点击: 次
平时自己写了很多代码,但从没好好计算总共写了多少行,面试时被问起来,就傻了。。。闲来无事,写个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)
上一篇:Python调用adb命令实现对多台设备同时进行reboot的方法
栏 目:Python代码
下一篇:Python django搭建layui提交表单,表格,图标的实例
本文标题:Python实现计算文件夹下.h和.cpp文件的总行数
本文地址:http://www.codeinn.net/misctech/15835.html






