From d46982681a7a36c4216d41098a3f71b395d9b71d Mon Sep 17 00:00:00 2001 From: Brett Bieber Date: Fri, 14 Nov 2008 18:41:09 +0000 Subject: [PATCH] add some examples for DirectoryIterator. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@269010 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/spl/directoryiterator.xml | 5 ++- reference/spl/directoryiterator/construct.xml | 43 +++++++++++++++---- reference/spl/directoryiterator/isdot.xml | 33 +++++++++++--- reference/spl/directoryiterator/islink.xml | 41 +++++++++++++++++- 4 files changed, 104 insertions(+), 18 deletions(-) diff --git a/reference/spl/directoryiterator.xml b/reference/spl/directoryiterator.xml index a82cdae566..d9e7579fb6 100644 --- a/reference/spl/directoryiterator.xml +++ b/reference/spl/directoryiterator.xml @@ -1,5 +1,5 @@ - + The DirectoryIterator class DirectoryIterator @@ -10,7 +10,8 @@
&reftitle.intro; - ... + The DirectoryIterator class provides a simple interface for viewing + the contents of filesystem directories.
diff --git a/reference/spl/directoryiterator/construct.xml b/reference/spl/directoryiterator/construct.xml index 183a9517ad..60966ec4ff 100644 --- a/reference/spl/directoryiterator/construct.xml +++ b/reference/spl/directoryiterator/construct.xml @@ -1,5 +1,5 @@ - + DirectoryIterator::__construct @@ -13,10 +13,8 @@ stringpath - &warn.undocumented.func; - - Constructs a new dir iterator from a path. + Constructs a new directory iterator from a path. @@ -28,18 +26,45 @@ path - The path. + The path of the directory to iterate. - - - &reftitle.returnvalues; + + + &reftitle.examples; - &return.void; + + A <methodname>DirectoryIterator::__construct</methodname> example + + This example will list the contents of the directory containing the script. + + +isDot()) { + echo 'Filename '.$fileinfo->getFilename().PHP_EOL; + } +} +?> +]]> + + + + + + + &reftitle.seealso; + + + SplFileInfo class + Iterator interface + diff --git a/reference/spl/directoryiterator/isdot.xml b/reference/spl/directoryiterator/isdot.xml index fa8bcd6c7f..13e82cdb8f 100644 --- a/reference/spl/directoryiterator/isdot.xml +++ b/reference/spl/directoryiterator/isdot.xml @@ -1,5 +1,5 @@ - + DirectoryIterator::isDot @@ -12,11 +12,9 @@ - &warn.undocumented.func; - - Check whether it's a directory and either . - or ... + Check whether the current entry is a directory and either + . or ... @@ -32,6 +30,31 @@ otherwise &false; + + + &reftitle.examples; + + + A <methodname>DirectoryIterator::isDot</methodname> example + + This example will list all files, omitting the . and + .. entries. + + +isDot()) { + echo 'Filename '.$fileinfo->getFilename().PHP_EOL; + } +} +?> +]]> + + + + diff --git a/reference/spl/directoryiterator/islink.xml b/reference/spl/directoryiterator/islink.xml index 8fa96595ce..011299a10e 100644 --- a/reference/spl/directoryiterator/islink.xml +++ b/reference/spl/directoryiterator/islink.xml @@ -1,5 +1,5 @@ - + DirectoryIterator::isLink @@ -15,7 +15,7 @@ &warn.undocumented.func; - Checks if the entry is a symbolic link. + Checks if the current element is a symbolic link. @@ -30,6 +30,43 @@ &true; if the entry is a symbolic link, otherwise &false; + + + &reftitle.examples; + + + A <methodname>DirectoryIterator::isLink</methodname> example + + This example contains a recursive function for removing a directory tree. + + +isFile() || $fileinfo->isSymlink()) { + unlink($fileinfo->getPathName()); + } elseif (!$fileinfo->isDot() && $fileinfo->isDir()) { + removeDir($fileinfo->getPathName()); + } + } + rmdir($path); +} + +removeDir('foo'); +?> +]]> + + + +