Posted by Peter van Schie on 07/23/06 14:15
laredotornado@zipmail.com schreef:
> Hello, Using PHP 4, is there a fucntion that counts the files in a
> given directory? You can assume there are no sub-directories within
> this directory and hence, no files within the sub-directories.
>
> Thanks for any functions or one-liners. - Dave
Hi Dave,
You could use readdir to accomplish this.
Example:
<?php
function countFiles($strDirName)
{
if ($hndDir = opendir($strDirName))
{
$intCount = 0;
while (false !== ($strFilename = readdir($hndDir)))
{
if ($strFilename != "." && $strFilename != "..")
{
$intCount++;
}
}
closedir($hndDir);
}
else
{
$intCount = -1;
}
return $intCount;
}
echo countFiles("C:\\Temp");
?>
HTH.
Peter.
--
http://www.phpforums.nl
[Back to original message]
|