List the contents of a directory using a while loop with FilesystemIterator::next in PHP

Description

The following code shows how to list the contents of a directory using a while loop with FilesystemIterator::next.

Example


<?php/*from  www . ja  v a 2  s .  co  m*/
$iterator = new FilesystemIterator(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