I found an old post with the almost perfect code for my problem: counting (many) files in a directory. It excludes the . en .. entries, but not other directories. I added a question by adding comment, but got no reply there. (too old post, i suppose) (Count how many files in directory php)
$fi = new FilesystemIterator(images, FilesystemIterator::SKIP_DOTS);
printf("There were %d Files", iterator_count($fi));
Searched at php.net, but a lot of this subject is not documented. I did find the SKIP_DOTS fact, but not one letter about how to exclude directories.
Now my code produces: There were 76849 Files but this includes the subdirectories too.
How do I change this code, so my subdirectories are excluded?
UPDATE BECAUSE OF SOME ANSWERS
/**
PHP version problem, need update first
$files = new FilesystemIterator('images');
$filter= new CallbackFilterIterator($files, function($cur, $key, $iter) {
return $cur->isFile();
});
printf('There were %d Files', iterator_count($filter));
*/
$time0 = time();
$fi = new FilesystemIterator(images, FilesystemIterator::SKIP_DOTS);
$fileCount = 0;
foreach ($fi as $f) {
if ($f->isFile()) {
$fileCount++;
}
}
printf("xThere were %d Files", $fileCount);
$time1 = time();
echo'<br />tijd 1 = '.($time1 - $time0); // outcome 5
echo'<hr />';
$fi = new FilesystemIterator(images, FilesystemIterator::SKIP_DOTS);
printf("yThere were %d Files", iterator_count($fi));
$time2 = time();
echo'<br />tijd 2 = '.($time2 - $time1); // outcome: 0
The first answer i cant use now, because i have to update my PHP version. When measuring time, the second answer takes much more time to proces.
I also noted, because of the second answer, my own code does not count files in subdirectories, it only counts the amount of subdirectories, in my case just 4. So for speed, i will use my own code and sbstract 4 of it. next week i try to update my php-version and will try again.
Thank you all for your contribution!!!