我有这个工作功能找到文件夹并创建一个数组.
function dua_get_files($path) { foreach (glob($path . "/*",GLOB_ONLYDIR) as $filename) { $dir_paths[] = $filename; } return $dir_paths; }
此功能只能在当前位置找到目录.我想查找子文件夹及其子目录中的目录路径等等.
数组应该是目录路径的平面列表.
$dir_path[0] = 'path/folder1'; $dir_path[1] = 'path/folder1/child_folder1'; $dir_path[2] = 'path/folder1/child_folder2'; $dir_path[3] = 'path/folder2'; $dir_path[4] = 'path/folder2/child_folder1'; $dir_path[5] = 'path/folder2/child_folder2'; $dir_path[6] = 'path/folder2/child_folder3';
如果你想递归地处理目录,你应该看看
原文链接:https://www.f2er.com/php/131203.htmlRecursiveDirectoryIterator
.
$path = realpath('/etc'); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),RecursiveIteratorIterator::SELF_FIRST); foreach($objects as $name => $object){ echo "$name\n"; }