You are here: Dose PHP support recursive call? Walk through all subdir « PHP Programming Language « IT news, forums, messages
Dose PHP support recursive call? Walk through all subdir

Posted by RC on 06/08/05 16:36

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);
}
?>

You see above I tried to used three different methods
to check a directory.

* 1st way I used filetype() function
I got errors

Warning: filetype(): Lstat failed for 05 in /MyPath/myreaddir.php on line 13
file is 05

Warning: filetype(): Lstat failed for 06 in /MyPath/myreaddir.php on line 13
file is 06

Where 05, 06 are sub-directories, it fails return a string "dir"! Why?!

2nd way I used is_dir() function, but it fails return true! Why?!

file is 05
file is 06


3rd way I used strcmp for return from file type, it gets the same
error as 1st way.


But when I tried to use

var_dump(is_dir("Documents/2005/05"));
var_dump(filetype("Documents/2005/05"));

I got the CORRECT display

bool(true)
string(3) "dir"

Can anyone out there help solve this mystery?
Thank Q very much in advance!

 

Navigation:

[Reply to this 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

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