-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineCounter.py
executable file
·41 lines (35 loc) · 1.12 KB
/
lineCounter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
########################################################
########################################################
## Laboratoire Specification et Verification
##
## Line counter script
##
## Author: Etienne ANDRE
##
## Created : 06/04/2009
## Last modified : 06/04/2009
########################################################
########################################################
########################################################
## IMPORTED MODULES
########################################################
import os, re
# Counter of lines
counter = 0
# Number of files
nb_files = 0
# Iterate on the files of the current directory
for file in os.listdir('.'):
# Only consider files
if os.path.isfile(file):
# Open file
file_object = open(file, 'r')
string_file = file_object.read()
# Count lines
nb_lines = len(re.findall("\n", string_file)) + 1
counter = counter + nb_lines
nb_files = nb_files + 1
# Print on screen
print " File " + file + ": " + str(nb_lines) + " lines"
# Print final result
print "IMPERATOR contains " + str(counter) + " lines of code in " + str(nb_files) + " files."