我正在尝试列出所有不包含文件koala.jpg的文件夹,我尝试了这种方法:
$iterator = new GlobIterator('/storage/websites/site/images/menu_slider/*/koala.*', GlobIterator::CURRENT_AS_PATHNAME);
if (!$iterator->count()) {
echo 'No matches';
} else {
$n = 0;
printf("Matched %d item(s)\r\n".'<br />', $iterator->count());
foreach ($iterator as $item) {
printf("[%d] %s\r\n".'<br />', ++$n, $iterator->key()).'<br />';
}
}
唯一的问题是,它只列出包含koala.jpg的文件,我需要知道哪些文件夹不包含它。以及如何获得每个的*(在这种情况下为235x141)的值?
它返回:
Matched 14 item(s)
[1] /storage/websites/site/images/menu_slider/235x141/koala.jpg
[2] /storage/websites/site/images/menu_slider/235x200/koala.jpg
[3] /storage/websites/site/images/menu_slider/240x100/koala.jpg
[4] /storage/websites/site/images/menu_slider/240x200/koala.jpg
[5] /storage/websites/site/images/menu_slider/250x200/koala.jpg
[6] /storage/websites/site/images/menu_slider/250x300/koala.jpg
[7] /storage/websites/site/images/menu_slider/250x400/koala.jpg
[8] /storage/websites/site/images/menu_slider/365x200/koala.jpg
[9] /storage/websites/site/images/menu_slider/470x200/koala.jpg
[10] /storage/websites/site/images/menu_slider/470x60/koala.jpg
[11] /storage/websites/site/images/menu_slider/480x100/koala.jpg
[12] /storage/websites/site/images/menu_slider/595x200/koala.jpg
[13] /storage/websites/site/images/menu_slider/960x100/koala.jpg
[14] /storage/websites/site/images/menu_slider/960x200/koala.jpg
任何帮助都非常偏见。
答案 0 :(得分:1)
使用dirname($iterator->key())
另外,请注意basename(dirname($iterator->key()))
仅在需要时获取最后一个文件夹名称