How to change a recursive function for count files and catalogues?
<pre><code>&lt;?php
function scan_dir($dirname)   {
$file_count = 0 ;     
$dir_count = 0 ;      
$dir = opendir($dirname);
while (($file = readdir($dir)) !== false) {
if($file != "." &amp;&amp; $file != "..")  {
if(is_file($dirname."/".$file))
++$file_count;
if(is_dir($dirname."/".$file)) {
++ $dir_count;
scan_dir($dirname."/".$file);
}
}
}
closedir($dir);
echo "There are $dir_count catalogues and $file_count files.&lt;br&gt;";
}

$dirname = "/home/user/path";
scan_dir($dirname);
?&gt;  
</code></pre>

<p>Hello,<br>
I have a recursive function for count files and catalogues. It returns result for <strong>each</strong> catalogue.<br>
But I need a <strong>common</strong> result. How to change the script? <br>
<em>It returns :</em><br>
There are 0 catalogues and 3 files.<br>
There are 0 catalogues and 1 files.<br>
There are 2 catalogues and 14 files. <br>
<em>I want:</em><br>
There are 2 catalogues and 18 files.<br></p>
