I'm trying to find a list of files in a directory tree. In essence I provide a text file with all the terms I want to search for (~500) and have it look for them in a directory and subdirectories. However, I'm having problems with - I believe - the steps that the code takes and ends prematurely without searching in all folders.
The code I'm using is (pattern is the name of a text file):
import os
def locateA(pattern, root):
file = open(pattern, 'r')
for path, dirs, files in os.walk(root):
for word in files:
for line in file:
if line.strip() in word:
print os.path.join(path, word), line.strip()
Any ideas on where I'm mistaken?
with open(pattern, 'rU') as f:and don't call your filefilebecausefileis a class in the builtin module.