Page 1 of 1

How do I get the file count and total mb used in a directory

Posted: Wed Apr 09, 2003 9:57 pm
by 3dron
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

Posted: Thu Apr 10, 2003 8:09 am
by Rob the R
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:

Code: Select all

$totalsize += filesize($file) ;
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