RE: [PHP] counting files
| From: | Andrew Rush | Date: | Fri, 16 Feb 2001 20:19:23 +0000 |
| Subject: | RE: [PHP] counting files | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-40216@lists.php.net to get a copy of this message | ||
On Friday, February 16, 2001, at 10:31 AM, Hoover, Josh wrote:
> Try this bit of code and see if it works. (I don't know if there's a less
> taxing (on the server) way to get a count of files in a directory or not.)
this code snippet won't work as a standalone. you are referencing an object that does not
exist.
> $myDirectory = dir("yourdirectory");
> while($entry=$myDirectory->read())
> {
> $filecount++;
> }
> $myDirectory->close();
>
you are on the right track though. if you are sure that everything in the directory
$d=opendir("path/to/my/directory");
$i=0;
while($found=readdir($d)) {
if($found != "." && $found != "..") {
$i++;
}
}
print("there were $i files found.");
:: Andrew Rush :: Lead Systems Developer :: MaineToday.com ::
**************************************************************************
"Crippled but
free, blind all the time, i was learning to see"
- J. Garcia / R. Hunter
**************************************************************************
The views expressed
herein are not necessarily those of my employer, but
they let me have them anyway.