Created
December 28, 2010 03:15
-
-
Save axiixc/756858 to your computer and use it in GitHub Desktop.
Quickly tells some info about a directory of text files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php # Axiixc [ 2010 ] | |
function exByteSize($bytes) | |
{ | |
$size = $bytes / 1024; | |
if ($size < 1024) | |
{ | |
$size = number_format($size, 2); | |
$size .= ' KB'; | |
} | |
else | |
{ | |
if ($size / 1024 < 1024) | |
{ | |
$size = number_format($size / 1024, 2); | |
$size .= ' MB'; | |
} | |
else if ($size / 1024 / 1024 < 1024) | |
{ | |
$size = number_format($size / 1024 / 1024, 2); | |
$size .= ' GB'; | |
} | |
else if ($size / 1024 / 1024 / 1024 < 1024) | |
{ | |
$size = number_format($size / 1024 / 1024 / 1024, 2); | |
$size .= ' TB'; | |
} | |
} | |
return $size; | |
} | |
$input = $argv[1]; | |
$files = array(); | |
if (is_dir($input)) | |
{ | |
$files = scandir($input); | |
foreach ($files as $key => $value) | |
$files[$key] = $input . '/' . $value; | |
} | |
else | |
$files[] = $input; | |
$numLines = 0; | |
$numFiles = 0; | |
$size = 0; | |
foreach ($files as $file) | |
{ | |
if (substr($file, -9) != '.DS_Store' && !is_dir($file)) | |
{ | |
$numLines += count(file($file)); | |
$numFiles++; | |
$size = filesize($file); | |
} | |
} | |
printf("Files %d\nLines %d\nSize %s\n", $numFiles, $numLines, exByteSize($size)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment