how to scan a directory with this code


//$a = scandir("/path/to/dir");
$a = scandir(".");
$f = create_function('$v', 'return preg_match("/.*\.htm$/", $v);');
$a = array_values(array_filter($a, $f));
// $a[0] now contains the file name
//$file_name = "*.htm";
$file_name = $a[0];

$html = implode('', file($file_name)) or die("Cant open file!");

id like to scan all the sub directory's too

unless you know a better way to write this, im open

thank you in advance for any code and help you may provide
Who is Participating?
AlexanderRConnect With a Mentor Enterprise Web DeveloperCommented:
The way i see it in your exampe is that you just need a list of all HTM files in the directory and subdirectories without knowing exactly where in the tree the file is.

Here's your code rearanged to fulfill recursive directory scan requirement:

function ListHTML($path){
   $a = scandir($path);
   foreach($a as $key => $name){
      if($name != "." && $name != ".."){
         } else {
               echo $name."<br>";
JohnnyAuthor Commented:
thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.