Generate an HTML directory tree in Python
<p>does anyone know of a way I can turn a directory path into a tree as follows (using Python 2.7)...</p>

<pre><code>&lt;div&gt;
    &lt;p class="toggle"&gt;item one&lt;/p&gt;
    &lt;div class="child"&gt;

        &lt;p&gt;contained&lt;/p&gt;

        &lt;p class="toggle"&gt;item&lt;/p&gt;
        &lt;div class="child" hidden="true"&gt;
            &lt;p&gt;inner&lt;/p&gt;
        &lt;/div&gt;

        &lt;p class="toggle"&gt;item&lt;/p&gt;
        &lt;div class="child" hidden="true"&gt;
            &lt;p&gt;inner&lt;/p&gt;

            &lt;p class="toggle"&gt;wow&lt;/p&gt;
            &lt;div class="child" hidden="true"&gt;
                &lt;p&gt;waaay down&lt;/p&gt;
                &lt;p&gt;somefile.py&lt;/p&gt;
            &lt;/div&gt;

        &lt;/div&gt;

        &lt;p class="toggle"&gt;item&lt;/p&gt;
        &lt;div class="child" hidden="true"&gt;
            &lt;p&gt;inner&lt;/p&gt;
        &lt;/div&gt;

    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p><strong>Edit:</strong>
the directory that would create the above output would look like this...</p>

<pre><code>item one
-contained
-item
--inner
-item
--inner
--wow
---waaay down
---somefile.py
-item
--inner
</code></pre>

<p>Directories need to have the "toggle" class, and should be followed by a div containing the contents of that directory.</p>

<p>If anyone can figure this out, that would be great, thanks! I've been trying to figure this out for ages.</p>