File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414
1515args = parser .parse_args ()
1616
17+
18+ total_lines = 0
19+ total_words = 0
20+ total_characters = 0
21+ file_count = 0
22+
23+
1724def counter (item ):
1825 lines = len (item .strip ().split ("\n " ))
1926 words = len (item .split ())
@@ -38,46 +45,25 @@ def process_file(file_path):
3845 else :
3946 print (f"{ stats ['lines' ]} { stats ['words' ]} { stats ['characters' ]} { file_path } " )
4047
41-
4248 total_lines += stats ['lines' ]
4349 total_words += stats ['words' ]
4450 total_characters += stats ['characters' ]
4551 file_count += 1
4652
4753
48- total_lines = 0
49- total_words = 0
50- total_characters = 0
51- file_count = 0
5254
5355
5456for path in args .paths :
5557 if os .path .isfile (path ):
56-
57-
58-
59-
58+ process_file (path )
6059 elif os .path .isdir (path ):
6160 for file in os .listdir (path ):
6261 file_path = os .path .join (path , file )
63-
6462 if os .path .isfile (file_path ):
6563 with open (file_path , "r" ) as f :
6664 content = f .read ()
6765
68- if args .line :
69- print (f"{ stats ['lines' ]} { file_path } " )
70- elif args .word :
71- print (f"{ stats ['words' ]} { file_path } " )
72- elif args .char :
73- print (f"{ stats ['characters' ]} { file_path } " )
74- else :
75- print (f"{ stats ['lines' ]} { stats ['words' ]} { stats ['characters' ]} { file_path } " )
76-
77- total_lines += stats ['lines' ]
78- total_words += stats ['words' ]
79- total_characters += stats ['characters' ]
80- file_count += 1
66+
8167
8268
8369
You can’t perform that action at this time.
0 commit comments