get folder attributes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

get folder attributes

Post by yaron »

Hello all,
How can I get a folder's attributes.
I want to get the folder size,how many files are in it and most important the folder's date

Thank you
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You can try something like this for the directory size

Code: Select all

$dir = "dir"; 


function dirsize($checkdir) { 
    $dh = opendir($checkdir); 
    $size = 0; 
    while (($file = readdir($dh)) !== false) 
        if ($file != "." and $file != "..") { 
            $path = $checkdir."/".$file; 
            if (is_dir($path)) 
                $size += dirsize($path); 
            elseif (is_file($path)) 
                $size += filesize($path); 
        } 
    closedir($dh); 
 $formated_size = $size /1000; 
    return $formated_size; 
} 


$getFolderSize = dirsize("/files/personal");
Post Reply