平時自己寫了很多代碼,但從沒好好計算總共寫了多少行,面試時被問起來,就傻了。。。閑來無事,寫個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)
|
新聞熱點
疑難解答