searching files from a lot of files for a keyword and printing the sentence containing keyword,filename in python
Question: 
    import os
    path = 'C:\\Users\\Kabeer\\Documents\\testdata'
    listing = os.listdir(path)
    for infile in listing:
       read_f = open(infile)
       for line in read_f:
        if 'arch' in line:
         print(line)
    print ("current file is: " + infile)
    

I have placed all the files in a folder. I want to read each file for a
keyword. If it contains the keyword then print the name of file and entire
sentence containing keyword.

I am absolute beginner in python. The code above is also picked from
stackoverflow forum only.

I am getting error. File not found error read_f=open(infile).No such file or
directory.

I know error is in loop. How to put each file through loop? I tried also
putting all the files in list. But I am not able to get each file and read
from loop.

Thanks

Kabeer


Answer: Try use `read_f = open(os.path.join(path,infile))`

