Reply to Re: count files in a directory

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация