统计代码行数,代码行数,TotalLine.py


TotalLine.py

#/usr/bin/pythonimport os#count the line of a single filedef CountLine(path):        tempfile = open(path)        res = 0        for lines in tempfile:                res += 1        print "%s %d" %(path, res) #output the file path and lines        return res#count the total line of a folder, sub folder includeddef TotalLine(path):        total = 0        for root, dirs, files in os.walk(path):                for item in files:                        ext = item.split('.')                        ext = ext[-1]  #get the postfix of the file                        if(ext in ["cpp", "c", "h", "java", "py", "php"]):                                subpath = root + "/" + item                                total += CountLine(subpath)        return totalprint "Input Path"path = raw_input()print TotalLine(path)

评论关闭