Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: directory size

  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts

    directory size

    how can we find dir size?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Probably build a file list in the dir via glob() and use filesize to tally the size of all the files in the dir. You'll want to make it recursive so it tallies files inside dirs inside the dirs.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by zodehala View Post
    how can we find dir size?
    try:

    http://www.php.net/manual/en/function.stat.php

    in comment secion post of marting.dc AT gmail.com and addition of JulieC

    PHP Code:
    <?
    function dir_size($dir)
    {
        
    $handle opendir($dir);
        
    $mas 0;
        while (
    $file readdir($handle)) {
            if (
    $file != '..' && $file != '.' && !is_dir($dir.'/'.$file)) {
                
    $mas += filesize($dir.'/'.$file);
                } else if (
    is_dir($dir.'/'.$file) && $file != '..' && $file != '.') {
                
    $mas += dir_size($dir.'/'.$file);
            }
        }
        return 
    $mas;
    }
    echo 
    dir_size('DIRECTORIO').' Bytes';
    ?>
    I don't test this.

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •