0

我正在尝试列出所有不包含文件 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 

非常感谢任何帮助。

4

1 回答 1

0

利用dirname($iterator->key())

另外,basename(dirname($iterator->key()))如果需要,请注意仅获取最后一个文件夹名称

于 2013-10-15T18:19:10.593 回答