title: Count files in directory, but exclude subdirectories
body: <p>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)
  (<a href="https://stackoverflow.com/questions/12801370/count-how-many-files-in-directory-php/12801806#12801806">Count how many files in directory php</a>)</p>
  
  <pre><code>$fi = new FilesystemIterator(images, FilesystemIterator::SKIP_DOTS);
  printf("There were %d Files", iterator_count($fi));
  </code></pre>
  
  <p>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.</p>
  
  <p>Now my code produces: There were 76849 Files
  but this includes the subdirectories too.</p>
  
  <p>How do I change this code, so my subdirectories are excluded?</p>
  
  <p>UPDATE BECAUSE OF SOME ANSWERS</p>
  
  <pre><code>/**
  PHP version problem, need update first
  
  $files = new FilesystemIterator('images');
  $filter= new CallbackFilterIterator($files, function($cur, $key, $iter) {
  return $cur-&gt;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-&gt;isFile()) {
          $fileCount++;
      }
  }
  printf("xThere were %d Files", $fileCount);
  
  $time1 = time();
  echo'&lt;br /&gt;tijd 1 = '.($time1 - $time0); // outcome 5
  
  echo'&lt;hr /&gt;'; 
  
  
  $fi = new FilesystemIterator(images, FilesystemIterator::SKIP_DOTS);
  printf("yThere were %d Files", iterator_count($fi));
  $time2 = time();
  echo'&lt;br /&gt;tijd 2 = '.($time2 - $time1); // outcome: 0
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thank you all for your contribution!!!</p>