View Single Post
Old 03-11-2008, 11:16 PM   #11 (permalink)
freenity
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

didn't want to create a new thread because the topic is really similar.
I was trying to make a recursive function just to count how many files are in a dir and it's subdirectories:

PHP Code:
<?php

$dir 
"/var/www/html/";


$files getfilesnum($dir);


echo 
$files." files in {$dir} and subdirs<br />";

closedir($dh);


function 
getfilesnum($d)
{
    
$dh opendir($d);
    
$files 0;
    while (
$f readdir($dh))
    {
        if (
filetype($d.$f) == 'file')
        {
            
$files++;
        }
        elseif ((
filetype($d.$f) == 'dir') && ($f != '.') && ($f != '..'))
        {
            
$files += getfilesnum($d.$f);
        }
    }
    return 
$files;
}

?>
Isn't working :S it doesn't go recursive, don't know why. Any idea??

I saw that CHASE in his code put all the directories in a array and then called the recursive function, but it should work without using the array I think...

Aah I posted twice, please delete it admins :)
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote