Weird DirectoryIterator behaviour

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guillermobytes
    New Member
    • Jan 2010
    • 77

    Weird DirectoryIterator behaviour

    Hello,

    can someone make light on this please :

    i have a path to a dir:
    Code:
    $path = "/var/www/Tests";
    echo $path;
    the output is :
    Code:
    /var/www/Tests
    when i create a new DirectoryIterat or like this :
    Code:
    $dirIt = new DirectoryIterator($path);
    and ask php if it is a directory, it says its not!
    Code:
    if (!$dirIt->isDir()) {
        echo "This is not a directory!";
    }
    the output is :
    Code:
    This is not a directory!
    and
    Code:
    print_r($dirIt);
    output is a FILE!!
    Code:
    DirectoryIterator Object
    (
        [pathName:SplFileInfo:private] => /var/www/Tests/enginecartelmania.php
        [fileName:SplFileInfo:private] => enginecartelmania.php
        [glob:DirectoryIterator:private] => 
        [subPathName:RecursiveDirectoryIterator:private] => 
    )
    can someone make sense to this?

    thanks for your help
  • guillermobytes
    New Member
    • Jan 2010
    • 77

    #2
    Sorry, I was very tired... The answer is that DirectoryIterat or iterates through the directory contents. So when i ask if the current element in DirectoryIterat or is a directory, except when the directory iterator is pointing at the . and .. directories, the answer will allways be no!
    The right way to do this is to call is_dir($path)
    sorry for stupid post

    Comment

    Working...