Jump to content

DirectoryIterator not working -- HELP


KaptainBlazzed

Recommended Posts

I have a script the iterates through my directories allowing users to transverse and download files.

 

It was up and running just fine until i switched servers, both were running PHP 5.x.x and ISS 7.

 

The issue is no matter what directory i run the script in, the DirectoryIterator returns a bunch of "." or a "$Recycle.Bin" if i set it to the look in "C:/"

 

 

Here is the code:

<?

$cwd = "c:/";

foreach (new DirectoryIterator($cwd) as $file) {

echo $file->getFilename(). "\n";

}

?>

 

Here is the output from "C:/"

$Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin $Recycle.Bin

 

Here is the output if is set $cwd to "."

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

 

I can not figure this out and am beginning to think it is a permissions issue. :shrug:

 

any help would be appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/213521-directoryiterator-not-working-help/
Share on other sites

getcwd() returns the following

 

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

 

 

I have tried it in several different directories, including my web root and it always returns the same result, a bunch of "."

 

i do however get a different # of "." depending on the directory.

Try that and postback the output:

 

$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
    if (!$fileinfo->isDot()) {
        var_dump($fileinfo->getFilename());
    }


}

 

No output because they are all "."

 

This is really starting to bug me and i can not figure it out.

 

Could it be a setting in the config file?

this work for me:

 

<?php 
  
   $path = 'C:/TEST/';

   foreach (new DirectoryIterator($path) as $fileInfo) {
       if($fileInfo->isDot()) continue;

       echo $fileInfo->getFilename() . "<br>\n";
   }	

?>

 

You should look at RecursiveDirectoryIterator too

 

http://php.net/manual/en/class.recursivedirectoryiterator.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.