Newbie recursive directory
| From: | Kim Kohen | Date: | Mon, 10 Feb 2003 22:28:39 +0000 |
| Subject: | Newbie recursive directory | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135128@lists.php.net to get a copy of this message | ||
G'day all
I've been trying for a day or so to get a script to traverse all the levels
of a directory. With help from list archives and web sites I've come up
with this:
<?php
$the_array = Array();
$thedir = "/Users/kim/test/";
$handle = opendir($thedir);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file !=
".DS_Store")
{
$the_array[] = $thedir . $file;
}
}
closedir($handle);
foreach ($the_array as $i)
{
$fileinfo = fopen(($i), "r") OR die("Failed to open file $i");
$thedata = fread($fileinfo, filesize($i));
fclose($fileinfo);
echo "$i $thedata<br>";
}
?>
I've read lots f stuff about "if (is_dir($blah)" but I get a bit lost with
the navigation after that (I'm _real_ new to *nix as well). Could someone
please help as to how it would fit into my script?
Cheers and thanks
kim