Scandir scan all sub folder infinetly
<p>I have a large piece of code which does a lot of things with folder, files names etc. However, I seemed to have hit an interesting issue.</p>

<p>I am scanning a directory <code>./wp-content/uploads/webvideos/</code></p>

<pre><code>$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach($iterator as $file) echo $file . "&lt;br /&gt;";

$iterator = $files;

$files = array();
$webdir = site_url()."/wp-content/uploads/webvideos/";
</code></pre>

<p>This gives me the first level in the array. Is there an easy way to get it to scan the 1st, 2rd, 3rd etc. </p>

<p>New code  </p>

<pre><code> $path = "./wp-content/uploads/webvideos/";

    $webdir = site_url()."/wp-content/uploads/webvideos/";
    $post_title = html_entity_decode(get_the_title());

    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS));
    $files = array();
    $notAllowedExtension = array('jpg', 'mp3', 'vtr');

    foreach($iterator as $file){

        if(!in_array($file-&gt;getExtension(), $notAllowedExtension) &amp;&amp; !$file-&gt;isDir())
            $files[filemtime($file-&gt;getPathname())] = $file-&gt;getPathname(); 

    }

    ksort($files);

    echo "&lt;pre&gt;" . print_r($files, true) . "&lt;/pre&gt;";
</code></pre>