統計本身寫的代碼量

python作的統計

用到的模塊python

  • os
  • time

代碼code

#!/usr/bin/env 
#coding:utf-8
import os
import time

def analysePath(basePath):
    for basedir,dirs,files in os.walk(basePath):
        for ofile in files:
            filePath = os.path.join(basedir,ofile)
            check_file(filePath)
        for odir in dirs:
            newBasePath = os.path.join(basedir,odir)
            analysePath(newBasePath)

def check_file(filePath):
    global totalCount
    with open(filePath,'r') as f:
        lines = f.readlines()
        if 'User: cs_sharp' in ''.join(lines[0:10]):
            for line in lines:
                if ''.join(line.split()) == '':totalCount+=1
            print len(lines),filePath

totalCount = 0
if __name__ == '__main__':
    analysePath('D:\Projects\projectB')
    print totalCount
相關文章
相關標籤/搜索