Python: Files stop being opened at a certain point
<p>I've written the following program in Python:</p>

<pre><code>import re
import os
import string

folder = 'C:\Users\Jodie\Documents\Uni\Final Year Project\All Data'

folderlisting = os.listdir(folder)
for eachfolder in folderlisting:
    print eachfolder
    if os.path.isdir(folder + '\\' + eachfolder):
        filelisting = os.listdir('C:\Users\Jodie\Documents\Uni\Final Year Project\All Data\\' + eachfolder)
        print filelisting

        for eachfile in filelisting:
            if re.search('.genbank.txt$', eachfile):
                genbankfile = open(eachfile, 'r')
                print genbankfile

            if re.search('.alleles.txt$', eachfile):
                allelesfile = open(eachfile, 'r')
                print allelesfile
</code></pre>

<p>It looks through a lot of folders, and prints the following:</p>

<ol>
<li>The name of each folder, without the path</li>
<li>A list of all files in each folder</li>
<li>Two specific files in each folder (Any files containing ".genbank.txt" and ".alleles.txt").</li>
</ol>

<p>The code works until it reaches a certain directory, and then fails with the following error:</p>

<pre><code>Traceback (most recent call last):
  File "C:\Users\Jodie\Documents\Uni\Final Year Project\Altering Frequency Practice\Change_freq_data.py", line 16, in &lt;module&gt;
    genbankfile = open(eachfile, 'r')
IOError: [Errno 2] No such file or directory: 'ABP1.genbank.txt'
</code></pre>

<p>The problem is:</p>

<ol>
<li>That file most definitely exists, since the program lists it before it tries to open the file.</li>
<li>Even if I take that directory out of the original group of directories, the program throws up the same error for the next folder it iterates to. And the next, if that one is removed. And so on.</li>
</ol>

<p>This makes me think that it's not the folder or any files in it, but some limitation of Python? I have no idea. It has stumped me.</p>

<p>Any help would be appreciated.</p>
