代码如下:
import sys,os def afileline(f_path): res=0 f=open(f_path,"r",1,"utf8") for lines in f: if(lines.split()): res+=1 return res if(__name__=='__main__'): host='/root/workspace/' print(host) allline=0 allfiles=0 for root,dirs,files in os.walk(host): if(root.startswith(host+os.sep+'adodb5')): continue if(root.startswith(host+os.sep+'corephpexcel')): continue if(root.startswith(host+os.sep+'exteditor')): continue for afile in files: if(afile in ['PHPExcel.php', 'jquery-1.5.2.js', 'jquery-ui.js','jquery-ui.css','timer.js']): continue ext=afile.split('.') ext=ext[-1] if(ext in ['py','xml']): itpath=root+os.sep+afile allfiles+=1 allline+=afileline(itpath) print ('Total lines:',allline) print ('Total: ',allfiles)