#!/usr/bin/python
"""
Count the number of lines in files recursively in a given directory.
To run direct rather than from the command line, switch the last line around.
"""
import os
import sys
def count_lines(f):
counter = 0
f = open(f, "r")
for line in f.read().split('\n'):
counter += 1
f.close()
return counter
def count_dir(dirname):
counter = 0
for f in os.listdir(dirname):
fa = os.path.join(dirname, f)
if os.path.isdir(fa):
dcount = count_dir(fa)
counter = counter + dcount
else:
fcount = count_lines(fa)
counter = counter + fcount
return counter
#print count_dir(r"C:\stuff")
print count_dir(sys.argv[1])