rewinddir

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

rewinddirReinicia el gestor de directorio

Descripción

rewinddir(?resource $dir_handle = null): void

Reinicia el flujo de directorio indicado por dir_handle al principio del directorio.

Parámetros

dir_handle
Un gestor de directorio resource previamente abierto con opendir(). Si dir_handle es null se utilizará el último gestor abierto usando opendir().

Valores devueltos

No se retorna ningún valor.

Historial de cambios

Versión Descripción
8.5.0 Usar null para dir_handle ahora está obsoleto. En su lugar, debe proporcionarse explícitamente el último gestor de directorio abierto.
8.0.0 dir_handle ahora es nullable.

Ejemplos

Para un ejemplo completo, consulte la documentación de opendir().

Ver también

  • opendir() - Abrir un manejador de directorio
  • readdir() - Leer entrada desde el manejador de directorio
  • closedir() - Cerrar el gestor de directorio
  • dir() - Devuelve una instancia de la clase Directory
  • is_dir() - Indica si el fichero es un directorio
  • glob() - Búsqueda de rutas que coinciden con un patrón
  • scandir() - Lista los ficheros y directorios en un directorio
add a note

User Contributed Notes 2 notes

up
6
ASchmidt at Anamera dot net
7 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.
up
6
osamahussain897 at gmail dot com
7 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
To Top