PHP 7.3.0 alpha 2 Released

rewinddir

(PHP 4, PHP 5, PHP 7)

rewinddirRetourne à la première entrée du dossier

Description

void rewinddir ([ resource $dir_handle ] )

rewinddir() retourne à la première entrée du dossier identifiée par dir_handle.

Liste de paramètres

dir_handle

La ressource de dossier ouverte précédemment avec opendir(). Si la ressource de dossier n'est pas fournie, la dernière ressource ouverte avec la fonction opendir() sera utilisée.

Valeurs de retour

Cette fonction retourne NULL en cas de succès ou FALSE si une erreur survient.

add a note add a note

User Contributed Notes 2 notes

up
1
osamahussain897 at gmail dot com
4 months ago
/* Source Code */

<?php
$dir
= "/images/";

// Open a directory, and read its contents
if (is_dir($dir)){
  if (
$dh = opendir($dir)){
   
// List files in images directory
   
while (($file = readdir($dh)) !== false){
      echo
"filename:" . $file . "<br>";
    }
   
rewinddir();
   
// List once again files in images directory
   
while (($file = readdir($dh)) !== false){
      echo
"filename:" . $file . "<br>";
    }
   
closedir($dh);
  }
}
?>

/* Result */

filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
up
0
ASchmidt at Anamera dot net
9 days ago
It is crucial to note that rewinddir() does not simply start over at the beginning of the SAME directory list. Instead, this function first re-reads the directory - thus any file that were deleted (or inserted) since the original opendir() will be reflected after "rewinding".

In that respect, rewinddir() is equivalent to a closedir(), opendir() sequence, but without obtaining a new handle.
To Top