How to change a recursive function for count files and catalogues?
        Posted  
        
            by 
                user661999
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user661999
        
        
        
        Published on 2011-03-16T07:52:40Z
        Indexed on 
            2011/03/16
            8:09 UTC
        
        
        Read the original article
        Hit count: 201
        
php
<?php
function scan_dir($dirname)   {
$file_count = 0 ;     
$dir_count = 0 ;      
$dir = opendir($dirname);
while (($file = readdir($dir)) !== false) {
if($file != "." && $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.<br>";
}
$dirname = "/home/user/path";
scan_dir($dirname);
?>  
Hello,
I have a recursive function for count files and catalogues. It returns result for each catalogue.
But I need a common result. How to change the script? 
It returns :
There are 0 catalogues and 3 files.
There are 0 catalogues and 1 files.
There are 2 catalogues and 14 files. 
I want:
There are 2 catalogues and 18 files.
© Stack Overflow or respective owner