Return Month and Year Directory Names and Folder Sizes
<p>I have a directory that contains subdirectories of Year (e.g. 2009), and within these sub directories contain sub directories of months (e.g. 02)</p>

<p>I need to calculate the total files in each month folder, along with the total file size for each folder, and out put the two totals (Total Size &amp; Total Files) along with the year and month folder names.</p>

<p><strong>Example:</strong></p>

<ul>
<li><p>05/2009 - 512MB (12 Files)</p></li>
<li><p>06/2009 - 45KB (21 Files)</p></li>
<li><p>07/2009 - 6MB (8 Files)</p></li>
<li><p>01/2011 - 54MB (2 Files)</p></li>
<li><p>04/2011 - 652MB (55 Files)</p></li>
</ul>

<p>...</p>

<p>I have created the following function that will calculate the total size and file of a directory. How do I adapt it to cater for muti sub folders lists as outlined above?</p>

<pre><code>function foldersize($path) {
    $total_size = 0;
    $total_files = 0;

    $files = scandir($path);

    foreach($files as $file) {
        if ($t&lt;&gt;"." &amp;&amp; $t &lt;&gt; "..") {
            if (is_dir($path.'/'.$file)) {
                $size = foldersize($path.'/'.$file);
                $total_files++;
                $total_size += $size;
            }
            else {
                $size = filesize($path.'/'.$file);
                $total_files++;
                $total_size += $size;
            }
        }   
    }

    return $total_size.' | '.$total_files;
}
</code></pre>
