note 41636 modified in ref.spl by nlopess
| From: | nlopess@php.net | Date: | Thu, 29 Apr 2004 14:30:35 +0000 |
| Subject: | note 41636 modified in ref.spl by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69005@lists.php.net to get a copy of this message | ||
Here's a sample implementation of the RecursiveDirectoryIterator class. It prints a simple
treeview of a given directory:
<?php
function recurse($it) {
echo '<ul>';
for( ; $it->valid(); $it->next()) {
if($it->isDir() && !$it->isDot()) {
printf('<li class="dir">%s</li>', $it->current());
if($it->hasChildren()) {
$bleh = $it->getChildren();
echo '<ul>' . recurse($bleh) . '</ul>';
}
} elseif($it->isFile()) {
echo '<li class="file">'. $it->current() . ' (' .
$it->getSize(). ' Bytes)</li>';
}
}
echo '</ul>';
}
recurse(new RecursiveDirectoryIterator('D:/'));
?>
--was--
Here's a sample implementation of the RecursiveDirectoryIterator class. It prints a simple
treeview of a given directory:
<?php
function recurse($it) {
echo '<ul>';
for( ; $it->valid(); $it->next()) {
if($it->isDir() && !$it->isDot()) {
printf('<li class="dir">%s</li>', $it->current());
if($it->hasChildren()) {
$bleh = $it->getChildren();
printf('<ul>%s</ul>');
echo '<ul>' . recurse($bleh) . '</ul>';
}
} elseif($it->isFile()) {
printf('<li class="file">%s (%u Bytes)</li>',
$it->current(), $it->getSize());
}
}
echo '</ul>';
}
recurse(new RecursiveDirectoryIterator('D:/'));
?>
http://www.php.net/manual/en/ref.spl.php