Personal tools
You are here: Home GNU/Linux Scripting Line Counter
Log in


Forgot your password?
New user?
 

Line Counter

by Srecko Toroman last modified Oct 23, 2008 01:11 AM

I use this script occasionally to check how much code I've written so far :)

So, here I'm using os.walk method which is basically an iterator that returns a triplet (path, directories, files) on each iteration. Method "walk" is doing a deep first search of the filesystem recursively (by default, can be turned off by a parameter topdown=False) and basically I just open every file and read lines (tho' I can't stress how much this code can be faster, smarter etc - this is the point of scripts - keep it simple, stupid).

#!/usr/bin/env python

import os

tot = 0



for path,b,c in os.walk("."):

    mc = 0

    for f in [each for each in c if each.endswith(".java")]:

        fd = open(os.path.join(path,f))

        for each in fd:

            mc += 1

        fd.close()

    print "In %s\t: %d lines." % (path, mc)

    tot += mc



print "Total: %d lines!" % (tot,)

There are currently no items in this folder.

Document Actions
« November 2009 »
November
MoTuWeThFrSaSu
1
2345678
9101112131415
16171819202122
23242526272829
30