(PHP 5 >= 5.1.2, PHP 7)
RecursiveDirectoryIterator::__construct — Construye un RecursiveDirectoryIterator
$path
[, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO
] )
Construye un RecursiveDirectoryIterator()
para el path proporcionado.
pathLa ruta de el directorio a ser iterado.
flagsSe pueden proporcionar flags para afectar el comportamiento de algunos métodos. Una lista de flags puede encontrarse en Constantes predefinidas FilesystemIterator. También se pueden establecer más tarde con FilesystemIterator::setFlags().
Devuelve el RecursiveDirectoryIterator recién creado.
Lanza una UnexpectedValueException
si el path no puede ser encontrado o este no es un directorio.
Ejemplo #1 Ejemplo de RecursiveDirectoryIterator
<?php
$directorio = '/tmp';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directorio));
$it->rewind();
while($it->valid()) {
if (!$it->isDot()) {
echo 'SubPathName: ' . $it->getSubPathName() . "\n";
echo 'SubPath: ' . $it->getSubPath() . "\n";
echo 'Key: ' . $it->key() . "\n\n";
}
$it->next();
}
?>
El resultado del ejemplo sería algo similar a:
SubPathName: fruta/manzana.xml SubPath: fruta Key: /tmp/fruta/manzana.xml SubPathName: stuff.xml SubPath: Key: /tmp/stuff.xml SubPathName: vegetales/zanahoria.xml SubPath: vegetales Key: /tmp/vegetales/zanahoria.xml