(PHP 5 >= 5.1.2, PHP 7, PHP 8)
RecursiveDirectoryIterator::__construct — Constrói um RecursiveDirectoryIterator
$directory, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO)
Constrói um RecursiveDirectoryIterator()
para o directory fornecido.
directoryO caminho do diretório a ser iterado.
flagsAs opções (flags) podem ser fornecidas e afetarão o comportamento de alguns métodos. Uma lista das opções (flags) pode ser encontrada em Constantes predefinidas de FilesystemIterator. Elas também podem ser definidas posteriormente com FilesystemIterator::setFlags().
Lança uma UnexpectedValueException
se o directory não existir.
Lança um ValueError
se o directory for uma string vazia.
| Versão | Descrição |
|---|---|
| 8.0.0 |
Agora lança um ValueError se
directory for uma string vazia;
anteriormente lançava um RuntimeException.
|
Exemplo #1 Exemplo de RecursiveDirectoryIterator
<?php
$directory = '/tmp';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
$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();
}
?>O exemplo acima produzirá algo semelhante a:
SubPathName: fruit/apple.xml SubPath: fruit Key: /tmp/fruit/apple.xml SubPathName: stuff.xml SubPath: Key: /tmp/stuff.xml SubPathName: veggies/carrot.xml SubPath: veggies Key: /tmp/veggies/carrot.xml