Previously UsedBashImplemented (Http://www.cnblogs.com/MikeZhang/archive/2012/08/22/linesCountBash20120822.html), But that cannot beWindowsSo I wrotePythonIt is also convenient for me to use later ......I don't know much about it here.Google.
ImplementationCode
# ! /Usr/bin/Python ''' File: Count. py Author: Mike E-mail: Mike_Zhang@live.com ''' Import Sys, osextens = [ " . 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 + = 1Print Fname l_count = Len (open (fname). readlines ()) Print Fname, " : " , L_count linescount + = Rochelle 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: " , Linescountraw_input ( " Press enter to continue " )
Usage
1For the local directory
./Count. py
2Statistics on multiple directories
./Count. py/tmp ~
Running Effect
Okay, that's all. I hope it will help you.