Get the current DirectoryIterator item in PHP

Description

The following code shows how to get the current DirectoryIterator item.

Example


// w  w  w  . jav  a2  s  .  c  o  m
//list the contents of the directory containing the script
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
while($iterator->valid()) {
    $file = $iterator->current();
    echo $iterator->key() . " => " . $file->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