title: PHP List Directory structure and exclude some directories
body: <p>I have this PHP Code:</p>
  
  <pre><code>$rootpath = '../admin/';
  $inner = new RecursiveDirectoryIterator($rootpath);
  $fileinfos = new RecursiveIteratorIterator($inner);
  
  foreach ($fileinfos as $pathname =&gt; $fileinfo)
  {
      $pathname2 = substr($pathname,2);
      $sql = "SELECT * from admin_permissions where page_name = '$pathname2'";
      $rs = mysql_query($sql,$conn);
      if (mysql_num_rows($rs) == 0)
      {
          if (!$fileinfo-&gt;isFile()) continue;
          $sql2 = "INSERT into admin_permissions (page_name) values ('$pathname2')";
          $rs2 = mysql_query($sql2,$conn);
          echo "$pathname&lt;br&gt;";
      }
  }
  </code></pre>
  
  <p>That is displaying my directory structure and inserting the directories and file names into a database (removing the first 2 characters <code>..</code>).</p>
  
  <p>Since the <code>RecursiveDirectoryIterator</code> iterates through all files in all directories, how can I exclude whole directories, including all files within them?</p>