[ PHP | JavaScript ]
Code Name: Get Folder Stats
Added: 24/09/06 By: Ross This will produce information about any directory and its sub-folders that you set it to read such as total files, total file size and total lines.
<?php
/******************************************
*
* Find Statistics on Files & Folders
* Written By http://freelancedev.net
* Redistribute and use freely
* but keep this header intact
*
*******************************************/
$total_file_size = 0;
$total_files = 0;
$total_directories = 0;
$total_lines = 0;
function read_dir($dir) {
if($handle = opendir($dir)) {
global $total_directories;
global $total_files;
global $total_file_size;
global $total_lines;
if(preg_match('/^.{1,2}$/', $dir)) {
$dir = '';
} else {
$dir .= '/';
}
$total_directories++;
while (false !== ($file = readdir($handle))) {
$total_files++;
$file = $dir . $file;
if(is_dir($file)) {
if(!preg_match('/.{1,2}$/', $file)) {
read_dir($file);
}
} else if(!preg_match('/Thumbs/', $file)) {
$total_lines += sizeof(file($file));
$total_file_size += filesize($file);
}
}
}
}
function add_commas($num) {
return preg_replace('/(d+)(d{3})/', '$1,$2', $num);
}
read_dir('.');
$total_file_size = add_commas(floor($total_file_size / 100));
$total_lines = add_commas($total_lines);
echo "Total Directories Opened: $total_directories";
echo "Total Files Scanned: $total_files";
echo "Total File Size: $total_file_size Mb";
echo "Total Lines Read: $total_lines";
?>
/******************************************
*
* Find Statistics on Files & Folders
* Written By http://freelancedev.net
* Redistribute and use freely
* but keep this header intact
*
*******************************************/
$total_file_size = 0;
$total_files = 0;
$total_directories = 0;
$total_lines = 0;
function read_dir($dir) {
if($handle = opendir($dir)) {
global $total_directories;
global $total_files;
global $total_file_size;
global $total_lines;
if(preg_match('/^.{1,2}$/', $dir)) {
$dir = '';
} else {
$dir .= '/';
}
$total_directories++;
while (false !== ($file = readdir($handle))) {
$total_files++;
$file = $dir . $file;
if(is_dir($file)) {
if(!preg_match('/.{1,2}$/', $file)) {
read_dir($file);
}
} else if(!preg_match('/Thumbs/', $file)) {
$total_lines += sizeof(file($file));
$total_file_size += filesize($file);
}
}
}
}
function add_commas($num) {
return preg_replace('/(d+)(d{3})/', '$1,$2', $num);
}
read_dir('.');
$total_file_size = add_commas(floor($total_file_size / 100));
$total_lines = add_commas($total_lines);
echo "Total Directories Opened: $total_directories";
echo "Total Files Scanned: $total_files";
echo "Total File Size: $total_file_size Mb";
echo "Total Lines Read: $total_lines";
?>