All pastes #11279 Raw Edit

Anonymous

public python v1 · immutable
#11279 ·published 2005-05-09 06:13 UTC
rendered paste body
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'<script.*?>', re.IGNORECASE)#    html = regexp.sub('<script language="MonthyPythonsScript">',html)#    file = open(filepath, 'w+')#    file.write(html)#    file.close()     print "Comments in "+sys.argv[1]+" are: "+repr(count)if len(sys.argv) > 1 :    stripscripts( sys.argv[1] )else:    print message