Python calculates the total number of. h and. cpp files in a folder,
I usually write a lot of code myself, but I never calculate the total number of lines I have written. It's silly to be asked during the interview... Nothing to worry about. Write a python program for statistics.
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 + '\') # recursively read all files if OS. path. splitext (fullPath) [1] in (". h ",". cpp "): file = open (fullPath) for eachLine in file. readline (): lineCount + = 1 file. close () failed t Exception as e: print (e) return lineCount ###################################### ######################################## # if _ name _ = "_ main __": baseDir = "K: \ C ++ \ MFC \ BubbleDragon \" lineCount = calcLine (baseDir) print (lineCount)