|
-
May 16th, 2005, 04:59 PM
#1
Thread Starter
Frenzied Member
Size of a folder and all sub-folders...?
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
-
May 17th, 2005, 10:05 AM
#2
Lively Member
Re: Size of a folder and all sub-folders...?
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.
-
May 17th, 2005, 11:31 AM
#3
Lively Member
Re: Size of a folder and all sub-folders...?
maybe something like this:
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";
}
}
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.
EDIT: when looking at the scandir() function on php.net i found a custom scandir() function that a user submitted
PHP 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;
}
Works with php 4.3.10
Last edited by RyanEllis; May 17th, 2005 at 11:35 AM.
-
May 17th, 2005, 02:01 PM
#4
Thread Starter
Frenzied Member
Re: Size of a folder and all sub-folders...?
Yea, that could work - I'll try it later and let you know 
Cheers,
RyanJ
-
May 17th, 2005, 04:43 PM
#5
Re: Size of a folder and all sub-folders...?
-
May 17th, 2005, 05:13 PM
#6
Thread Starter
Frenzied Member
Re: Size of a folder and all sub-folders...?
 Originally Posted by visualAd
never heared of that function before, must have been added while I was not looking 
Cheers and thanks again,
RyanJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|