How to extract zip file recursively?
<p>I have a zip file which contains three zip files in it like this:</p>

<pre><code>zipfile.zip\  
    dirA.zip\
         a  
    dirB.zip\
         b  
    dirC.zip\
         c
</code></pre>

<p>I want to extract all the inner zip files that are inside the zip file in directories with these names (dirA, dirB, dirC).<br>
Basically, I want to end up with the following schema:</p>

<pre><code>output\  
    dirA\
         a  
    dirB\
         b  
    dirC\
         c
</code></pre>

<p>I have tried the following:</p>

<pre><code>import os, re
from zipfile import ZipFile

os.makedirs(directory)  # where directory is "\output"
with ZipFile(self.archive_name, "r") as archive:
    for id, files in data.items():
        if files:
            print("Creating", id)
            dirpath = os.path.join(directory, id)

            os.mkdir(dirpath)

            for file in files:
                match = pattern.match(filename)
                new = match.group(2)
                new_filename = os.path.join(dirpath, new)

                content = archive.open(file).read()
            with open(new_filename, "wb") as outfile:
                outfile.write(content)
</code></pre>

<p>But it only extracts the zip file and I end up with:</p>

<pre><code>output\  
    dirA\
         dirA.zip 
    dirB\
         dirB.zip 
    dirC\
         dirC.zip
</code></pre>

<p>Any <em>suggestions including code-segments</em> will be much appreciated cause I have tried so many different things and read the docs without success.</p>