Logical python question - handling directories and files in them
<p>I'm using this function to extract files from .zip archive and store it on the server:</p>

<pre><code>def unzip_file_into_dir(file, dir):
    import sys, zipfile, os, os.path

    os.makedirs(dir, 0777)
    zfobj = zipfile.ZipFile(file)
    for name in zfobj.namelist():
        if name.endswith('/'):
            os.mkdir(os.path.join(dir, name))
        else:
            outfile = open(os.path.join(dir, name), 'wb')
            outfile.write(zfobj.read(name))
            outfile.close()
</code></pre>

<p>And the usage:</p>

<pre><code>unzip_file_into_dir('/var/zips/somearchive.zip', '/var/www/extracted_zip')
</code></pre>

<p>somearchive.zip have this structure:</p>

<pre><code>somearchive.zip
    1.jpeg
    2.jpeg
    another.jpeg
</code></pre>

<p>or, somethimes, this one:</p>

<pre><code>somearchive.zip
    somedir/
        1.jpeg
        2.jpeg
        another.jpeg
</code></pre>

<p>Question is: <strong>how do I modify my function, so that my <code>extracted_zip</code> catalog would always contain just images, not images in another subdirectory, even if images are stored in <code>somedir</code> inside an archive.</strong></p>
