Program to count the number of lines of code in your project !

This is a simple program in python which counts the total number of lines of code in a list of files from a directory.
 #Program to count the number of lines of code in project
#Author : Sreekumar
#
import sys
import fnmatch
import os
rootPath = sys.argv[1]
pattern = sys.argv[2]
total_lines = 0
lines = 0
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
filename = os.path.join(root, filename)
try:
f = open(filename,"r")
lines = len(f.readlines())
print filename + " : %d Lines"% lines
total_lines += lines
except IOError:
print "Some error"
print "\nTOTAL LINES : %s "% total_lines

Save this program as "yourfilename.py" and open a terminal
type

python yourfilename.py /yourprojectdir-path/ *.*

example :

python countlines.py "/home/x/mypro/" "*.php"

the last argumet *.php" specifies the pattern to be filtered from the list of files.

2 comments:

  1. I never thought I will come in contact with a real and potential hacker until I knew   brillianthackers800 at Gmail and he delivered a professional job,he is intelligent and understanding to control jobs that comes his way
    You can message on his number +1(385) 2501115,
    Contact him and be happy

    ReplyDelete
  2. i am a successful business owner and father. I got one of these already programmed blank ATM cards that allows me withdraw a maximum of $5,000 daily for 30 days. I am so happy about these cards because I received mine last week and have already used it to get $20,000. Skylink technology is giving out these cards to support people in any kind of financial problem. I must be sincere to you, when i first saw the advert, I believed it to be illegal and a hoax but when I contacted this team, they confirmed to me that although it is illegal, nobody gets caught while using these cards because they have been programmed to disable every communication once inserted into any Automated Teller Machine(ATM). If interested get through to them on mail: skylinktechnes@yahoo.com  or  whatsapp/telegram: +1(213)785-1553  

    ReplyDelete