示例,仅返回树中指定深度的目录
<?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);
$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;
}
?>