本文整理汇总了PHP中RecursiveIteratorIterator::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveIteratorIterator::getChildren方法的具体用法?PHP RecursiveIteratorIterator::getChildren怎么用?PHP RecursiveIteratorIterator::getChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveIteratorIterator
的用法示例。
在下文中一共展示了RecursiveIteratorIterator::getChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: folder
public function folder($path, $recursive = false, $types = null)
{
$dirs = $files = array();
if (is_dir($path)) {
$cut = strlen($path);
$regex = $types ? '/^.+\\.(' . $types . ')$/i' : false;
$dir = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
if ($recursive) {
$dir = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
if (is_int($recursive)) {
$dir->setMaxDepth($recursive);
}
}
foreach ($dir as $file) {
$path = str_replace('\\', '/', substr($file->getRealpath(), $cut));
if ($file->isDir()) {
if (iterator_count($dir->getChildren()) === 0) {
rmdir($file->getRealpath());
// might as well do some garbage collection while we are at it
} else {
$dirs[] = $path;
}
} elseif ($types !== false) {
if ($regex) {
if (preg_match($regex, $file->getFilename())) {
$files[] = $path;
}
} else {
$files[] = $path;
}
}
}
}
return array($dirs, $files);
}