Consider this code for traversing through a directory structure:


function traverse($path='.') {
   $path = realpath($path);
   $dir = opendir($path);

   echo "\nDirectory : $path\n";
   echo str_pad('',76,'-')."\n";

   while (false !== ($file = readdir($dir))) {
     if (is_dir($file) && $file != '.' && $file != '..') {
       echo $file;


echo '<pre>';
echo '</pre>';


Now when I run it in a directory that has a file with spaces in it's 
name.. for examples purposes, the file willbe called "file name with 

Directory : /home/mike/php/test
Warning:  stat failed for file name with spaces (errno=2 - No such file 
or directory) in /home/mike/php/dirdump.php on line 10

Any ideas why this error happens and what I can do to get around it?


PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to