Before using Bash (http://www.bitsCN.com/article/61943.htm), but that can't be used under Windows, so I wrote a python version, it is also convenient for me to use later ... Here is not more introduced, do not understand the Google under.
Implementation code
The code is as follows:
#!/usr/bin/python
'''
File:count.py
Author:mike
E-mail:mike_zhang@live.com
'''
Import Sys,os
Extens = [". C", ". cpp", ". hpp", ". H")
Linescount = 0
Filescount = 0
def funcount (dirName):
Global Extens,linescount,filescount
For Root,dirs,filenames in Os.walk (dirName):
For F in FileNames:
fname = Os.path.join (root,f)
Try:
ext = F[f.rindex ('. '):]
if (extens.count (EXT) > 0):
print ' Support '
Filescount + = 1
Print fname
L_count = Len (open (fname). ReadLines ())
Print fname, ":", L_count
Linescount + = L_count
Else
Print ext, ": not support"
Except
Print "Error occur!"
Pass
If Len (SYS.ARGV) > 1:
For M_dir in sys.argv[1:]:
Print M_dir
Funcount (M_dir)
else:
Funcount (".")
print "Files Count:", Filescount
Print "Lines count:", Linescount
Raw_input ("Press Enter to continue")
How to use
1. For this catalogue
The code is as follows:
./count.py
2. Count Multiple Catalogs
The code is as follows:
./count.py/tmp ~
Run effect
All right, that's it, I hope it helps you.