1

我只想通过使用列出主目录中的子目录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
)

可能吗?

4

1 回答 1

1
if ($fileObject->isDir()) {
    $files[] = $fileObject->getPathname();
}
于 2013-09-17T10:00:19.277 回答