Got error when putting DirectoryIterator() inside a for loop in PHP!
<p>This is my code to go through all special folder "<code>folderContainer</code>" which inside other drives:</p>

<pre><code>$folderNames = '';
// go through all drives.Just want to find out which has folderContainer
for($i='D';$i&lt;='Z';$i++){ 
     // get the path    
     $path = realpath($i.':\\folderContainer\\');

     $folders = new DirectoryIterator($path);

     foreach($folders as $folder){
         if($folder-&gt;isDot()) continue;
         // get folder's name which match my pattern
         if ($folder-&gt;isDir() &amp;&amp; preg_match('/^[A-Z]{1}[0-9]{1,9}$/i', $folders)){
              // store the folder name
              $folderNames .= ' '.$folder.' ';
          }
     } 
} 
</code></pre>

<p>And got these error messages:</p>

<pre><code>Fatal error: Uncaught exception 'RuntimeException' with message 'Directory name must not be empty.' 
</code></pre>

<p>But my code work correct when I set the <code>$path</code> to <code>"D:\\folderContainer\\"</code> without a loop. So, how can I to make the code to go through all <code>folderContainer</code> which inside other drives .</p>

<p>Thank you very much!!</p>
