title: How to use ::setMaxDepth for RecursiveIteratorIterator?
body: <p>I'm using this script but I would like to specify a max depth to the recursive function. I don't know how to use it, I always get an error. How should I use the <a href="http://php.net/manual/en/recursiveiteratoriterator.setmaxdepth.php" rel="nofollow">::setMaxDepth</a> here?</p>
  
  <pre><code>public function countFiles($path)
  { 
  global $file_count;
  $depth=0;
  $ite=new RecursiveDirectoryIterator($path);
  
  $file_count=0;
  foreach (new RecursiveIteratorIterator($ite) as $filename=&gt;$cur) :
      $file_count++;
      $files[] = $filename;
  endforeach;
  
  return $file_count;
  }
  </code></pre>