I am writing code that looks for a specific string that could occur in a vacancy. I have some vacancies in a local folder in a .txt format. I want to search all files for the string and then store that string in a new file that will contain all filenames.
I created a list that contains all vacancies because I do not want the new file containing the searched string to appear when I search for a string a second time
I have the following code:
import os
import glob
from datetime import date
import time
today = date.today()
d1 = today.strftime("%d/%m/%Y")
search = "engineer"
vacancies = [filename for filename in glob.glob("*.txt") if not filename.endswith('keyword.txt')]
for filename in vacancies:
with open ("C:\\LOCATION\\txt"+'\\'+filename, 'r', encoding='utf-8') as f:
for line in f:
line = line.lower
for filename in vacancies:
with open ("C:\\LOCATION\\txt"+'\\'+filename) as f:
if search in f.read():
f = open(d1 + " " + search + " keyword.txt","a+", encoding='utf-8')
f.write("Found it in " + filename + '\n')
f.close
I would expect my list to filter out the new file, however I get an errormessage stating: FileNotFoundError: [Errno 2] No such file or directory: '05/11/2020 engineer keyword.txt'
Can someone explain why this code is not working?
line = line.lowerhas no effect.05/11/2020 engineer keyword.txtto exist?