bux23
4/26/2017 - 10:33 AM

Find all files with specific extensions in directroy and subdirectories

Find all files with specific extensions in directroy and subdirectories

<?php

$extension = 'php';
$folder = 'folder';

if(file_exists($folder)) {
  $dir = new RecursiveDirectoryIterator($folder);
  foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
      if ($file->isFile() && $file->getExtension() == $extension) {
          echo $file->getPathname() . "<br />";
      }
  }
} else {
  echo 'folder not found';
}

?>