PHP 8.5.0 Alpha 1 available for testing

Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

spicypixel at gmail dot com
7 years ago
Example to only return directories that are a specified depth in a tree:

<?php
function directory_mapper($path)
{
$maxDepth = 3;
$minDepth = 3;
$iterator = new RecursiveIteratorIterator(
new
RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD// Ignore "Permission denied"
);
$iterator->setMaxDepth($maxDepth);

$paths = array($path);
foreach (
$iterator as $path => $dir) {
if (
$iterator->getDepth() >= $minDepth) {
if (
$dir->isDir()) {
$paths[] = $path;
}
}

}
array_shift($paths);
return
$paths;
}
?>

<< Back to user notes page

To Top