?
Solved

how to scan a directory with this code

Posted on 2007-08-02
2
Medium Priority
?
248 Views
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
0
Comment
Question by:Johnny
2 Comments
 
LVL 11

Accepted Solution

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

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
 

Author Comment

by:Johnny
ID: 19617984
thank you
0

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