Usually I wrote a lot of code, but never a good calculation of the total number of lines written, interview was asked up, silly ... Have nothing to do, write a python program to count
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)