Listing all folders in a menu system
<p>I'm trying to use scandir() to list all folders in a directory into a menu structure I am making.  Here is the code I have so far:</p>

<pre><code>$directory = "models/";
$files = scandir($directory);

echo "  &lt;a class=\"menuitem submenuheader\" href=\"#\" &gt;models&lt;/a&gt;
        &lt;div class=\"submenu\"&gt;\n
        &lt;ul&gt;\n";

foreach($files as $file)
{
     if(is_dir($file))
     {
        echo "&lt;li&gt;&lt;a href=\"$file.html\"&gt;$file&lt;/a&gt;&lt;/li&gt;\n";
     }
}
echo "&lt;/ul&gt;\n&lt;/div&gt;\n";
</code></pre>

<p>I think I'm having an issue in the if(is_dir($file) line of the code.
It is listing two items in the menu (.) and (..).</p>

<p>Thanks for any/all help that is offered!  I very much appreciate it.</p>

<p>To do some testing, I replaced the foreach loop with a for loop.</p>

<pre><code>$directory = "models/";
$folders = scandir($directory);

echo "&lt;a class=\"menuitem submenuheader\" href=\"#\" &gt;models&lt;/a&gt;\n";
echo "&lt;div class=\"submenu\"&gt;\n";
echo "&lt;ul&gt;\n";

for ($i=0; $i&lt;count($folders); $i++) {
     if ($folders[$i] != '.' &amp;&amp; $folders[$i] != '..') {
         if(is_dir($folders[$i])) {
            echo "&lt;li&gt;&lt;a href=\"" . $folders[$i] . ".html\"&gt;" . $folders[$i] . "&lt;/a&gt;&lt;/li&gt;\n";
         }
     }
}
echo "&lt;/ul&gt;\n&lt;/div&gt;\n";
</code></pre>

<p>Still doesn't work (Won't pull a folder within the $directory)
BUT, if I change the </p>

<pre><code>if(is_dir($folders[$i]))
</code></pre>

<p>to</p>

<pre><code>if(!is_dir($folders[$i]))
</code></pre>

<p>it lists all the files as well as the single folder in the $directory.
Not sure why it is doing this.  Any ideas?</p>
