It has been implemented in bash before (http://www.jb51.net/article/61943.htm), but that can't be used under Windows, so it's a Python version, and it's convenient for me to use later ... Here is not much introduced, do not understand the Google under.
Implementation code
Copy Code code 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 directory
Copy Code code as follows:
2. Count Multiple Catalogs
Copy Code code as follows:
Run effect
Well, that's all, I hope to help you.