python - How can I check if a string exists in any file within a directory / subdirectory? -


i have list of strings , print out not present within file in directory. (i don't want check headers)

i understand how loop through list, have been unable find out how search within files of directory.

here's i've got far:

import fnmatch import os  matches = [] root, dirnames, filenames in os.walk('browserclient'):   filename in fnmatch.filter(filenames, 'file.png'):     print filename 

this searches filenames , want instead search through every file in directory , sub directory.

you have open file:

import fnmatch import os  targets = ['hello', 'world', 'foo', 'bar'] matches = [] root, dirnames, filenames in os.walk('browserclient'):   filename in fnmatch.filter(filenames, 'file.png'):     word in open(filename, 'r').read().split():       item in target:         if word == item:           matches.append([filename, item])