<?php
/**
* @author Jamie Curnow
* This is an example of the Stats class working on all files in the specified directory.
* This example is meant to be run from the console command line of an operating system.
*/
require_once('file_stats.class.php');
$file_stats = new File_Stats();
// Change this directory to wherever you have large files.
$directory = '.';
// Loop over all items in this Directory
$directory_handle = @opendir($directory);
while (false !== ($file = @readdir($directory_handle))) {
// skip anything that starts with a '.' i.e.:('.', '..', or any hidden file)
if (substr($file, 0, 1) != '.') {
if ($file_stats->getFileType($directory.'/'.$file) == File_Stats::TYPE_DIR) {
// This is a Directory
print 'D '.str_pad($file, 50, ' ').' '.str_pad('', 30, ' ').' '.date('Y-m-d g:ia', $file_stats->getFileModifiedTime($directory.'/'.$file))."\n";
} else {
// This is a File
print 'F '.str_pad($file, 50, ' ').' '.str_pad(getReadableSize($file_stats->getFileSize($directory.'/'.$file)), 30, ' ').' '.date('Y-m-d g:ia', $file_stats->getFileModifiedTime($directory.'/'.$file))."\n";
}
}
}
function getReadableSize($bytes) {
if ($bytes >= 1024) {
$size_kb = round(($bytes / 1024),0);
if ($size_kb >= 1024) {
$size_mb = round(($bytes / 1024 / 1024),2);
if ($size_mb >= 1024) {
$size_gb = round(($bytes / 1024 / 1024 / 1024),2);
$sizer = number_format($size_gb, 2, '.', ',').' gig';
} else {
$sizer = number_format($size_mb, 2, '.', ',').' mb';
}
} else {
$sizer = number_format($size_kb, 0, '.', ',').' kb';
}
} else {
$sizer = $bytes.' b';
}
return $sizer;
}
?>
|