DirectoryIterator::isDir

(PHP 5)

DirectoryIterator::isDirDetermine if current DirectoryIterator item is a directory

Description

public bool DirectoryIterator::isDir ( void )

Determines if the current DirectoryIterator item is a directory.

Parameters

This function has no parameters.

Return Values

Returns TRUE if it is a directory, otherwise FALSE

Examples

Example #1 DirectoryIterator::isDir() example

This example lists the directories within the directory of the current script.

<?php
$iterator 
= new DirectoryIterator(dirname(__FILE__));
foreach (
$iterator as $fileinfo) {
    if (
$fileinfo->isDir()) {
        echo 
$fileinfo->getFilename() . "\n";
    }
}
?>

The above example will output something similar to:

.
..
apples
bananas
pears

See Also

Коментарии

Documentation is a bit misleading.

DirectoryIterator->isDir() and other classes (e.g. SplFileInfo->isDir()) return TRUE for symlinks of directories. Better use getType() method instead, which returns 'link' for symlinks.

This was reported long time ago - https://bugs.php.net/bug.php?id=72364 , but docs are still not fixed.
2019-06-20 12:16:59
http://php5.kiev.ua/manual/ru/directoryiterator.isdir.html

    Поддержать сайт на родительском проекте КГБ