how to scan a directory with this code

Posted on 2007-08-02
Medium Priority
Last Modified: 2008-02-01

//$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
Question by:Johnny
LVL 11

Accepted Solution

AlexanderR earned 2000 total points
ID: 19617522
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>";

Author Comment

ID: 19617984
thank you

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question