PHP Doku:: Constructs a RecursiveDirectoryIterator - recursivedirectoryiterator.construct.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige GrunderweiterungenStandard PHP Library (SPL)IteratorenThe RecursiveDirectoryIterator classRecursiveDirectoryIterator::__construct

Ein Service von Reinhard Neidl - Webprogrammierung.

The RecursiveDirectoryIterator class

<<The RecursiveDirectoryIterator class

RecursiveDirectoryIterator::getChildren>>

RecursiveDirectoryIterator::__construct

(PHP 5 >= 5.1.2)

RecursiveDirectoryIterator::__constructConstructs a RecursiveDirectoryIterator

Beschreibung

RecursiveDirectoryIterator::__construct ( string $path [, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO ] )

Constructs a RecursiveDirectoryIterator() for the provided path.

Parameter-Liste

path

The path of the directory to be iterated over.

flags

Flags may be provided which will affect the behavior of some methods. A list of the flags can found under FilesystemIterator predefined constants. They can also be set later with FilesystemIterator::setFlags().

Rückgabewerte

Returns the newly created RecursiveDirectoryIterator.

Fehler/Exceptions

Throws an UnexpectedValueException if the path cannot be found or is not a directory.

Beispiele

Beispiel #1 RecursiveDirectoryIterator example

<?php

$directory 
'/tmp';

$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));

while(
$it->valid()) {

    if (!
$it->isDot()) {
        echo 
'SubPathName: ' $it->getSubPathName() . "\n";
        echo 
'SubPath:     ' $it->getSubPath() . "\n";
        echo 
'Key:         ' $it->key() . "\n\n";
    }

    
$it->next();
}

?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

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

Siehe auch


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
pedro dot matamouros at gmail dot com
17.09.2010 14:43
You can use RecursiveDirectoryIterator::FOLLOW_SYMLINK as a flag to the constructor to have RecursiveDirectoryIterator follow symlinks, which it does not do by default.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)