Thread: Directory Size
View Single Post
  #1 (permalink)  
Old 07-30-2006, 07:25 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,569
Last Blog:
Tidy up your HTML
Credits: 0
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Directory Size

well i want to get the total size of a directory, ive managed to get this code to display the file size of every file in the directory

PHP Code:
<?php

$dir 
"../demo/themes/";
        
$tree = array();
        
$dirs = array(array($dir, &$tree));
       
        for(
$i 0$i count($dirs); ++$i)
        {
                
$d opendir($dirs[$i][0]);
                
$tier =& $dirs[$i][1];

                while(
$file readdir($d))
                {
                        if (
$file != '.' and $file != '..')
                        {
                                
$path $dirs[$i][0] . DIRECTORY_SEPARATOR $file;
                                if (
is_dir($path))
                                {
                                        
$tier[$file] = array();
                                        
$dirs[] = array($path, &$tier[$file]);
                                }
                                else
                                {
                                        
                                    
$size2 filesize($path);
                                    
$size = array($size2);
                                    
print_r($size);
                                    echo 
"<br>";    
                                        
                                }    
                                                                                 
                        }
                        
                }
                
        }
/*

?>
the only problem is adding all them together. my inital idea was to create a array that stores the file size in a new element then just create a loop that adds them all together. the only problem i have is every file size is stored in array element 0

HTML Code:
Array ( [0] => 0 )
Array ( [0] => 881 )
Array ( [0] => 97 )
Array ( [0] => 970 )
Array ( [0] => 1246 )
Array ( [0] => 0 )
Array ( [0] => 123 )
Array ( [0] => 1678 )
Array ( [0] => 1661 )
Array ( [0] => 2184 )
Array ( [0] => 8689 )
All help is appreciated, thank you.
Reply With Quote

Sponsored Links