note 58430 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 09 Nov 2005 06:15:43 +0000 |
| Subject: | note 58430 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98303@lists.php.net to get a copy of this message | ||
Note Submitter: cory at lavacube dot com
----
For Linux/Unix users:
A simple recursive way to get the total of a directory using the "du" command:
<?php
function du( $dir='./' )
{
// apply ending slash -- probably not necessary
$dir = (substr($dir, 0, -1)!='/'?$dir.'/':$dir);
// ensure path is a directory
if( !is_dir($dir) )
{
return 0;
}
// build command
$cmd = 'du -c "' .$dir. '" |grep total';
// run command
$dirsize = str_replace('total', null, cmd($cmd));
// output result
return trim($dirsize);
}
?>
This could more than likely be cleaned up, but it works. :-)