平时自己写了很多代码,但从没好好计算总共写了多少行,面试时被问起来,就傻了。。。闲来无事,写个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)
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com