This function, as far as I can tell, returns boolean, not string.
$di = new DirectoryIterator(/path/to/iterate);
while ($di->valid())
{
echo $di->getPathname() . "\n";
$di->next();
}
(PHP 5, PHP 7, PHP 8)
DirectoryIterator::valid — Vérifie si le répertoire contient encore des entrées
Vérifie si l'objet DirectoryIterator contient encore des fichiers.
Cette fonction ne contient aucun paramètre.
Retourne true
si la position est valide, et false
sinon;
Exemple #1 Exemple avec DirectoryIterator::valid()
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));
// Loop to end of iterator
while($iterator->valid()) {
$iterator->next();
}
$iterator->valid(); // FALSE
$iterator->rewind();
$iterator->valid(); // TRUE
?>
This function, as far as I can tell, returns boolean, not string.
$di = new DirectoryIterator(/path/to/iterate);
while ($di->valid())
{
echo $di->getPathname() . "\n";
$di->next();
}