我想使用以下代码获取没有子文件夹的主文件夹:
$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
RecursiveDirectoryIterator
或RecursiveIteratorIterator
是否有一个功能表明“这是主文件夹”?或者我是否必须使用一些变通方法代码?如果是,该代码将如何显示?
答案 0 :(得分: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);
}
}