Has anyone got a code that can get the size of a folder and all sub-folders - this is the last thing that I need and I've had no luck in solving it either.
Thanks in advance for the help,
RyanJ :)
Printable View
Has anyone got a code that can get the size of a folder and all sub-folders - this is the last thing that I need and I've had no luck in solving it either.
Thanks in advance for the help,
RyanJ :)
Here is an idea,
you could use the scandir() function to scan the folders for files, It will return an array with all of the files and then you could use the filesize() function to get the size of each file in the directory, which will give you the directory size.
Ryan.
maybe something like this:
Not: this code hasnt been tested, its mainly just to give you an idea, also scandir() function is only available in PHP5 i believe. But you can make your own custome one to suit your needs.PHP Code:function getDirSize($dir) {
IF (file_exists($dir))
{
$Files = scandir($dir);
For i = 0 To count($Files)
{
fSize = filesize($files[i]);
}
return fsize;
} else {
print "Directory:" . $dir . "Does not exist";
}
}
EDIT: when looking at the scandir() function on php.net i found a custom scandir() function that a user submitted
Works with php 4.3.10PHP Code:function scandir($dir, $no_dots=FALSE) {
$files = array();
$dh = @opendir($dir);
if ($dh!=FALSE) {
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
if ($no_dots) {
while(($ix = array_search('.',$files)) > -1)
unset($files[$ix]);
while(($ix = array_search('..',$files)) > -1)
unset($files[$ix]);
}
}
return $files;
}
Yea, that could work - I'll try it later and let you know :)
Cheers,
RyanJ
Quote:
Originally Posted by visualAd
never heared of that function before, must have been added while I was not looking ;)
Cheers and thanks again,
RyanJ