时间:2021-07-01 10:21:17 帮助过:68人阅读
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)