phpday 2027 - Call for Papers

rewinddir

(PHP 4, PHP 5, PHP 7, PHP 8)

rewinddir — Riporta all'inizio un handle di directory

Descrizione

function rewinddir(?resource $dir_handle = null): void

Reimposta lo stream di directory indicato da dir_handle all'inizio della directory.

Elenco dei parametri

dir_handle

Una resource di handle di directory aperta in precedenza con opendir(). Se dir_handle è null, viene usato l'ultimo handle aperto con opendir().

Valori restituiti

Nessun valore viene restituito.

Log delle modifiche

Versione Descrizione
8.5.0 L'uso di null per dir_handle è ora deprecato. Occorre invece fornire esplicitamente l'ultimo handle di directory aperto.
8.0.0 dir_handle ora è nullable.

Esempi

Per un esempio completo, consultare la documentazione di opendir().

Vedere anche:

  • opendir() - Apre l'handle della directory
  • readdir() - Legge una voce da un handle di directory
  • closedir() - Chiude un handle di directory
  • dir() - Return an instance of the Directory class
  • is_dir() - Dice se la stringa corrisponde ad una directory
  • glob() - Trova i percorsi che corrispondono a un pattern
  • scandir() - List files and directories inside the specified path

User Contributed Notes 2 notes

up
8
osamahussain897 at gmail dot com
8 years 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
4
ASchmidt at Anamera dot net
8 years 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.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top