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
JohnnyAsked:
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:

ListHTML("F:\books");
function ListHTML($path){
   $a = scandir($path);
   foreach($a as $key => $name){
      if($name != "." && $name != ".."){
         if(is_dir($path.'\\'.$name)){
            ListHTML($path.'\\'.$name);
         } else {
            if(preg_match("/.*\.htm$/",$name)){
               echo $name."<br>";
            }
         }
      }
   }
}
0
 
JohnnyAuthor Commented:
thank you
0
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.