Jump to content

Get size of a given directory??


Vivid Lust

Recommended Posts

<?php

function show_dir($dir, $pos=2){ 
    global $totalsize; 
    $handle = @opendir($dir); 
    while ($file = @readdir ($handle)){ 
        if (eregi("^\.{1,2}$",$file)) 
            continue; 
        if(is_dir($dir.$file)){ 
        show_dir("$dir.$file/", $pos+3); 
    }else{ 
        $size=filesize($dir.$file); 
        $totalsize=$totalsize+$size; 
        } 
    } 
    @closedir($handle); 

    return($totalsize); 
} 

$size = show_dir("path/to/dir/"); //returns size in bytes. trailing slash is required.

?>

 

I know you cant count files in a given directory

 

yes you can.

 

<?php
function count_files($dir){ 
     $count=0;
    $handle = @opendir($dir); 
    while ($file = @readdir ($handle)){ 
        if (eregi("^\.{1,2}$",$file)) 
            continue; 
        if(!is_dir($dir.$file)) {
        $count++; 
        } 
    } 
    @closedir($handle); 

    return($count); 
} 
$size = count_files("path/to/dir/"); //returns number of files in dir. trailing slash is required.
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.