Search all files in a folder
<p>I want to search "word" in many files in a folder. </p>

<p>I have already : </p>

<pre><code>route=os.listdir("/home/new")
for file in route:
</code></pre>

<p>This does not work : </p>

<pre><code> f = open ('' , 'r')
 for line in f : 
</code></pre>

<p>I tried this :</p>

<pre><code>for file in route:
    f = open(file, 'r')
    for line in f:
        if word in line:
            print(file)
            break
</code></pre>

<p>but I have an error :</p>

<pre><code>f=open( file ,'r')
IOError: [Errno 2] No such file or directory: file.txt
</code></pre>

<p>When I delete file.txt, next file , I receive the same error.</p>

<p>You already have it down mostly:</p>

<pre><code>for file in route:
    f = open(file, 'r')
    for line in f:
        if word in line:
            print(file)
            break
</code></pre>

python os.system