This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!\usr\bin\env python | |
import os | |
print 'current working directory : ' + os.getcwd() | |
total_lines = 0 | |
def number_of_lines_in_file( filename ): | |
global total_lines | |
if filename.endswith(".py"): | |
with open(os.path.realpath(filename), 'r') as file_handle: | |
lines = sum(1 for _ in file_handle) | |
print 'no of lines in ' + filename + ' is %d' %lines | |
total_lines = total_lines + lines | |
def visit_the_directory( folder ): | |
for element in os.listdir(folder): | |
if os.path.isdir(os.path.join(folder,element)): | |
print element + ' is a directroy' | |
dir = os.path.join(folder, element) | |
print '------------------------------' | |
print 'visiting folder ' + dir | |
startingTotalLines = total_lines | |
visit_the_directory(dir) | |
endingTotalLines = total_lines | |
LinesInThisModule = endingTotalLines - startingTotalLines | |
print 'total lines in ths module : %d' %LinesInThisModule | |
print 'total lines until now: %d' %(total_lines) | |
print 'exiting folder ' + dir | |
print '------------------------------' | |
else: | |
file = os.path.join(folder, element) | |
number_of_lines_in_file(file) | |
visit_the_directory(os.getcwd()) | |
print 'total lines : %d' %(total_lines) |