0

我想使用以下代码获取没有子文件夹的主文件夹:

$dir = new RecursiveDirectoryIterator($admin['data_folder_main'], FilesystemIterator::SKIP_DOTS);
$it = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
$it->setMaxDepth(1);

foreach($it AS $fileinfo) {
    if($fileinfo->isDir() AND !$it->isDot()) {
        echo $it->getSubPathName().'<br>';
    }
}

就像现在一样,此代码打印

main-folder
main-folder/subfolder
main-folder/subfolder

是否RecursiveDirectoryIteratorRecursiveIteratorIterator具有显示“这是主文件夹”的功能?还是我必须使用一些解决方法代码?如果是,该代码将如何显示?

4

1 回答 1

0

没关系!我这样修复它:

$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($admin['data_folder_main']), FilesystemIterator::SKIP_DOTS, RecursiveIteratorIterator::SELF_FIRST);

foreach($dir as $name => $object) {
    if($dir->isDir() AND !$dir->isDot()) {
        echo basename($name);
    }
}
于 2014-02-20T01:36:23.233 回答