#encoding=utf-8 import os,io,glob totlelines=0 totleNumber=0 dirposition=r"C:\usr\www\xfmh" phpLine=0 phpNumber=0 htmlLine=0 htmlNumber=0 cssLine=0 cssNumber=0 jsLine=0 jsNumber=0 #阿克东方丽景 def listyoudir(level, path): global totlelines global phpLine global htmlLine global cssLine global jsLine for i in os.listdir(path): filePath=path + '\\' + i if os.path.isfile(filePath): #if (filePath[filePath.rindex('.'):]==".css") or (filePath[filePath.rindex('.'):]==".js"): if (filePath[filePath.find('.'):] in [".php",".html",".css",".js"]): thisfileNum=0 totleNumber+=1 #html模板 if (filePath[filePath.find('.'):] in [".php"]): phpNumber+=1 for fileLine in open(filePath).xreadlines(): totlelines += 1 thisfileNum += 1 phpLine+=1 if (filePath[filePath.find('.'):] in [".html"]): htmlNumber+=1 for fileLine in open(filePath).xreadlines(): totlelines += 1 thisfileNum += 1 htmlLine+=1 if (filePath[filePath.find('.'):] in [".css"]): cssNumber+=1 for fileLine in open(filePath).xreadlines(): totlelines += 1 thisfileNum += 1 cssLine+=1 if (filePath[filePath.find('.'):] in [".js"]): jsNumber+=1 for fileLine in open(filePath).xreadlines(): totlelines += 1 thisfileNum += 1 jsLine+=1 print '| '*(level+1) + i +' number:'+str(thisfileNum) #if os.path.isdir(filePath) and i[0]!="." and i[:]!="yui": static目录 if os.path.isdir(filePath) and i[0]!="." : print '| '*(level+1) + i listyoudir(level+1, filePath) rootpath = os.path.abspath(dirposition) print rootpath listyoudir(0, rootpath) print "总行数:",totlelines print "php:",phpLine,"占",int(round((phpLine*1.0/totlelines)*100)) print "html:",htmlLine,"占",int(round((htmlLine*1.0/totlelines)*100)) print "css:",cssLine,"占",int(round((cssLine*1.0/totlelines)*100)) print "javascript:",jsLine,"占",int(round((jsLine*1.0/totlelines)*100))