| 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] |