I have a folder with lots of files, some of them contain one or several keywords, I also have a separate file, consisting of keywords only, a word per line, like this:
keyword1
keyword2
keyword3
I need to find all of these files.
So I have this code
import os
directory = os.listdir("D:/where_2_search")
with open('what_2search.txt','r') as searchlist:
for line in searchlist:
print(line)
for fname in directory:
if os.path.isfile("D:/where_2_search" + os.sep + fname):
searchedfile = open("D:/where_2_search" + os.sep + fname, 'r')
if line in searchedfile.read():
print('found string in file %s' % fname)
else:
print('string not found')
searchedfile.close()
But it doesn't work as I receive negative results only. How could I fix it?