File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ #-*- coding:utf-8 -*-
2+ import os
3+
4+ codeLines = 0
5+ commentLines = 0
6+ blankLines = 0
7+
8+ def CountLines (countDir ,ext ,ignore ):
9+
10+ global codeLines
11+ global commentLines
12+ global blankLines
13+
14+ for file in os .listdir (countDir ):
15+ if os .path .isdir (os .path .join (countDir ,file )) and file != ignore :
16+ CountLines (os .path .join (countDir ,file ),ext ,ignore )
17+ else :
18+ if os .path .splitext (file )[1 ].strip ('.' ) == ext :
19+ print (file )
20+ with open (os .path .join (countDir ,file ),'r' ,encoding = 'utf-8' ) as f :
21+ for line in f :
22+ if line .strip ().startswith ('#' ):
23+ commentLines = commentLines + 1
24+ elif line .strip () == '' :
25+ blankLines = blankLines + 1
26+ else :
27+ codeLines = codeLines + 1
28+
29+
30+
31+
32+ if __name__ == '__main__' :
33+ countDir = input ('文件夹路径:' )
34+ ext = input ('文件类型:' )
35+ ignore = input ('需要忽略的文件夹:' )
36+
37+ CountLines (countDir ,ext ,ignore )
38+ print ('代码行数:%d,注释行数:%d,空行数:%d' % (codeLines ,commentLines ,blankLines ))
You can’t perform that action at this time.
0 commit comments