平时自己写了很多代码,但从没好好计算总共写了多少行,面试时被问起来,就傻了。。。闲来无事,写个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怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号