<< back | print

file counter.php

This script counts specific file types in a folder:

<?
function countFiles($path, $extension)
{
$result = 0;
$handle=opendir($path);
while ($file = readdir ($handle))
{
if ($file != "." && $file != ".." && strpos($file,$extension))
$result++;
}
closedir($handle);
return $result;
}

$c1 = countFiles("../Folder", ".zip");
$c2 = countFiles("../Folder", ".gif");
$c3 = countFiles("../Folder", ".jpg");

echo "$c1 zip-files in folder <br />";
echo "$c2 gif-files in folder <br />";
echo "$c3 jpg-files in folder <br />";
?>