代码行统计工具

来源:互联网 发布:香港恐怖在线知乎 编辑:程序博客网 时间:2024/06/09 19:04

统计h/c/cpp/cc/代码,Python写的,只是统计了行数,没有区分空行,注释等

[python] view plain copy
  1. #! /usr/bin/python  
  2. # coding=utf-8  
  3. import os,sys  
  4. def getCount(dr):  
  5.     c = 0  
  6.     for l in os.listdir(dr):  
  7.         p = dr + '/' + l          
  8.         if os.path.isdir(p):  
  9.             c += getCount(p)  
  10.         if os.path.isfile(p):  
  11.             if l.endswith('.h'or /  
  12.                l.endswith('.c'or /  
  13.                l.endswith('.hpp'or /  
  14.                l.endswith('.cpp'or /  
  15.                l.endswith('.cc'):  
  16.                 t = len( open(p,'r').readlines() )  
  17.                 print p,t  
  18.                 c += t                  
  19.     return c  
  20. if __name__=="__main__":   
  21.     dr = sys.argv[1]  
  22.     print getCount(dr)  

 

自己这三年来,写的C/C++代码正文处理的代码有3万行,写的应用服务器近2万行,加起来也有5万行了;同时,python代码1万多行。平均到每个工作日将近80行,还行。

0 0
原创粉丝点击