tylerbutler.com
Tuesday, January 6 2009 @ 4:40 PM

Powered by Microsoft Office SharePoint Server 2007
Skip Navigation LinksTyler Butler.com / Life / Projects / Code Line Counter
                                                  
Code Line Counter 
It's official, HawkTour has 22,411 lines of code.
I have been working on HawkTour now for over two years, and I started wondering today exactly how much code we've generated since we started. I thought maybe Eclipse had a project-wide line counter somewhere, but I couldn't find it, so I just wrote a simple Python script to do it. The code is below.
# linecounter.py
# Tyler Butler, 03/08/2005
import os

total = 0
extensions = ['java', 'cpp', 'h']

for root, dir, files in os.walk('.'):
    for file in files:
        if str(file).split('.')[-1] in extensions:
            filename = os.path.join(root, file)
            f = open( filename )
            total += len(f.readlines())
            f.close()
            
print "TOTAL LINES IN PROJECT: " + str(total)
Pretty simple, isn't it? It just works in the current directory, but you can change that pretty easily. Also, if you want to add more extensions to count then just add them to the extensions list.
Suggested Browser: Mozilla Firefox
Theme and layout by Tyler Butler, original CSS classes from Axonz.com
Banner image from "Waiting for the World to Turn," by hermik.
Icons from: