使用glob()获取所有不以给定文本开头的文件

I understand how the following will return all files with a .txt extension. I would like to do the same but exclude those that start with 'exclude'? For instance, some/path/exclude_somefile.txt shouldn't be included.

$files = glob('/some/path/*.txt');

How can I do it?

I'm fairly certain that glob() uses a regex pattern, so you should be to filter it out using regex syntax. Try this:

$files = glob('/some/path/(?!exclude_)*.txt');

This uses a negative look-around, I'm not sure if glob() will understand it, but give it a shot.

EDIT:

glob() does not support high level regex functions such as look-arounds. Here's my suggestion.

$files = glob('/some/path/*.txt');

foreach($files as $key => $filename)
{
    if(strpos($filename, "/exclude_"))
        unset($files[$key]);
}