Further to zombat's use of the DirectoryIterator, it might also make sense to construct your own specialized filter class to make life easier (see the difference with the foreach
loops) and more reusable.
class DirectoryFilterThumbs extends FilterIterator {
public function __construct($path) {
parent::__construct(new DirectoryIterator($path));
}
public function accept() {
// Use regex or whatever you like here
return ($this->isFile() && strpos($this->getFilename(), "_thumb.") === FALSE);
}
}
$files = new DirectoryFilterThumbs("/dir/path");
foreach ($files as $file) {
echo $file->getFilename() . PHP_EOL;
}
Of course, if there is no need to do this in multiple places then the plain DirectoryIterator/condition combo given by zombat is perfectly suitable.