Check if current DirectoryIterator item is a directory in PHP

Description

The following code shows how to check if current DirectoryIterator item is a directory.

Example


//w  ww.  java2 s  .  c  om
//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 code above generates the following result.





















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip