我只想使用RecursiveIteratorIterator
,
$array_directories = array(
'core/controller/',
'core/model/',
'core/helper/'
);
foreach($array_directories as $path_directory){
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path_directory),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $fileObject) {
if ($fileObject->isDir()) {
$files[] = $fileObject;
}
}
}
print_r($files);
结果,
Array
(
[0] => SplFileInfo Object
(
[pathName:SplFileInfo:private] => core/controller\webfront
[fileName:SplFileInfo:private] => webfront
)
[1] => SplFileInfo Object
(
[pathName:SplFileInfo:private] => core/model\design
[fileName:SplFileInfo:private] => design
)
)
但我在追求,
Array
(
[0] => core/controller\webfront
[1] => core/model\design
)
有可能吗?
答案 0 :(得分:1)
if ($fileObject->isDir()) {
$files[] = $fileObject->getPathname();
}