PHP: DirectoryIterator::__construct - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DirectoryIterator::current CachingRecursiveIterator::hasChildren

Last updated: Fri, 26 Jan 2007

view this page in

# DirectoryIterator::__construct

(no version information, might be only in CVS)

DirectoryIterator::__construct -- Constructs a new dir iterator from a path

## Description

DirectoryIterator DirectoryIterator::__construct ( string path )

Внимание
К настоящему времени эта функция еще не была документирована; для ознакомления доступен только список аргументов.

add a note User Contributed Notes
DirectoryIterator::__construct
springub at northclick dot de
13-Dec-2006 04:26
`udvig dot ericson at gmail dot com
29-Jul-2006 07:48
In response to the comment below from udvig. The Example ist wrong, here is the right one:
<?php
$dir = new DirectoryIterator("/tmp");
foreach ($dir as $file) {
if ($file->isDot()) {
continue;
}
echo $file->getFilename() . "\n";
}
?>`
ludvig dot ericson at gmail dot com
28-Jul-2006 10:48
`In response to the comment below, you don't have to simulate a foreach(), DirectoryIterator obviously inherits SPL's Iterator interface, therefore:
<?php
$dir = new DirectoryIterator("/tmp");
foreach ($dir as $file) {
if ($dir->isDot()) {
continue;
}
echo $file . "\n";
}
?>`
fernandobassani at gmail dot com
25-Jan-2006 10:36
`We can now replace the old fashioned way of listing the content from a directory!
the old way:
<?php
if ($handle = opendir('/home/fernando/temp')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
print "$file <br />";
}
}
closedir($handle);
}
?>
the new way:
<?php
$dir = new DirectoryIterator('/home/fernando/temp');
while($dir->valid()) {
if(!$dir->isDot()) {
print $dir->current()."<br />";
}
$dir->next();
}
?>`
jakob dot buchgraber at gmail dot com
04-Jan-2006 07:36
`I wrote a function for finding all files in the current and in subdirectories.
The Code:
<?php
function getFiles(&$rdi,$depth=0) {
if (!is_object($rdi))
return;
for ($rdi->rewind();$rdi->valid();$rdi->next()) {
if ($rdi->isDot())
continue;
if ($rdi->isDir() || $rdi->isFile()) {
for ($i = 0; $i<=$depth;++$i)
echo '&nbsp;&nbsp;&nbsp;';
echo $rdi->current().'<br />';
if ($rdi->hasChildren())
getFiles($rdi->getChildren(),1+$depth);
}
}
}
getFiles(new RecursiveDirectoryIterator('.'));
?>`
add a note
DirectoryIterator::current CachingRecursiveIterator::hasChildren

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST