def stripscripts ( directoryStart ) : os.path.walk( directoryStart, callback, '' ) def callback ( args, directory, files ) : print 'Scanning',directory for fileName in files: if os.path.isfile( os.path.join(directory,fileName) ) : if string.lower(os.path.splitext(fileName)[1]) in ['.c','.cpp','.java','.h'] : countComments ( os.path.join(directory,fileName) ) def countComments ( filepath ) : print ' Processing',os.path.split(filepath)[1] file = open(filepath, 'rb') #can also try file.readlines() to put each line into a list # code = file.read() code = file.readlines() # file.close() #Do processing on comments Here slashstaropen = re.compile(".(/\*).") slashstarclose = re.compile("\*/") doubleslash = re.compile("//.*") comment = re.compile('/\*(.|[\r\n])*?\*/') count=0 for line in code: if doubleslash.search('line'): count = count + 1 print line if slashstaropen.search('line'): count = count + 1 print line if comment.search('line'): count = count + 1 print line # regexp = re.compile(r'', re.IGNORECASE) # html = regexp.sub('