Count lines of code

import os, re, sys
from os.path import join

rootdir = '/'
filter = '.*\.js$|.*\.py$|.*\.html$|.*\.css$|.*\.sql$|.*\.cs$|.*\.cpp$|.*\.c$|.*\.h|.*\.java$'


def usage():
    print 'USAGE: python loc.py /<rootdir>'

def loc(fname):
    try:
        f = open(fname)
        return len(f.readlines())
    except:
        return 0


def scan(dir):
    total = 0
    for root, dirs, files in os.walk(dir):
        for file in files:
            if re.match(filter, file):
                fullpath = os.path.join(root, file)
                ln = loc(fullpath)
                print fullpath, ln
                total += ln

    print '\n', '_'*34, '\n\n', 'Total # Of lines:', total, '\n\n'


if __name__ == '__main__':

    fname = ''
    args = sys.argv

    if len(args) >= 2:
        fname = args[1]
    else:
        fname = raw_input("Enter root directory: ")

    scan(fname)
    raw_input()