Move forward to next DirectoryIterator item in PHP

Description

The following code shows how to move forward to next DirectoryIterator item.

Example


//  w w w  .  j a  v a2s  .c om
//List the contents of a directory using a while loop.

<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
while($iterator->valid()) {
    echo $iterator->getFilename() . "\n";
    $iterator->next();
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




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