I am currently using " while(($file = $cldir->read()) !== false) " with a "++$filecount" to get me the total number of files in each directory.
Is there a better way?
Also how do I get the total file size of all the files in a directory?
THanks
Ron
How do I get the file count and total mb used in a directory
Moderator: General Moderators
This is a fine way to count the number of files in a directory. To find out the total size of all the files in that directory, use the filesize function in the while loop:
Just be careful that this will not count the size of the files contained in a subdirectory of the directory you specify. There is an example of a recursive function that calculates the total size of all the files contained in a directory and its subdirectories here:
http://www.php.net/manual/en/function.d ... .php#15203
Code: Select all
$totalsize += filesize($file) ;http://www.php.net/manual/en/function.d ... .php#15203