python processs complete list files matched

Posted by thomytheyon on Stack Overflow See other posts from Stack Overflow or by thomytheyon
Published on 2010-05-26T06:38:53Z Indexed on 2010/05/26 6:41 UTC
Read the original article Hit count: 215

Filed under:
|
|
|
|

Hi All,

I'm trying to get a simple code working, unfortunatly im a python beginner.

My script should return a list of files that doesn't match a pattern, more information here : http://stackoverflow.com/questions/2910106/python-grep-reverse-matching/2910288#2910288

My code is running but doesn't process the complete list of files found as it should :

import sys,os

filefilter = ['.xml','java','.jsp','lass']

path= "/home/patate/code/project"

s = "helloworld"

for path, subdirs, files in os.walk(path):

for name in files:

  if name[-4:] in filefilter :

     f = str(os.path.join(path, name))

     with open(f) as fp:

         if s in fp.read():

            print "%s has the string" % f

         else:

            print "%s doesn't have the string" % f

This code return :

/home/patate/code/project/blabla/blabla/build.xml doesn't have the string

None

If i change f = str(os.path.join(path, name)) for print str(os.path.join(path, name)) I can see the whole list being printed.

How can i process the whole list as i which to ? :(

Thanks again.

© Stack Overflow or respective owner

Related posts about python

Related posts about search