Reply to Re: Dose PHP support recursive call? Walk through all subdir

Your name:

Reply:


Posted by RC on 06/08/05 17:13

RC wrote:
> I assume the answer is yes.
>
> I try to write readSubdir function read all files
> in all sub-directories.
>
> <?php
> readSubdir("Documents/2005");
>
> function readSubdir($dirPath) {
> $dirPointer = opendir($dirPath);
> while (($file = readdir($dirPointer)) != false) {
> if ($file == "." || $file == "..")
> continue;
> if (filetype($file) == "dir") {
> # if (is_dir($file) == true) {
> # if (strcmp(filetype($file), "dir") == 0) {
> readSubdir($file);
> } else {
> echo "file is $file\n";
> }
> }
> closedir($dirPointer);
> }
> ?>
>

OK, I re-write the function, it is work, now.

<?php
readSubdir("Documents/2005");

function readSubdir($dirPath) {
chdir($dirPath);
$dirPointer = opendir(".");
while (($file = readdir($dirPointer)) != false) {
if ($file == "." || $file == "..")
continue; // skip current and upper directories
if (filetype($file) == "dir") {
# if (is_dir($file) == true) {
readSubdir($file);
} else {
echo "file is $file\n";
}
}
closedir($dirPointer);
chdir("..");
}
?>

Both filetype() and is_dir() functions are working fine.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация