# Readdir count certain files

**URL:** <https://forum.kirupa.com/t/readdir-count-certain-files/180404>\
**Category:** Uncategorized\
**Created:** [February 28, 2006, 2:01pm UTC](https://forum.kirupa.com/t/readdir-count-certain-files/180404 "2006-02-28T14:01:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul\_ferrie](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@paul\_ferrie](https://forum.kirupa.com/u/paul_ferrie)\
**Post date:** [February 28, 2006, 2:01pm UTC](https://forum.kirupa.com/t/readdir-count-certain-files/180404/1 "2006-02-28T14:01:00Z")

</div>

Hi guys  
I am trying to get a count of certain images i have in a folder.  
Images are as soon 1\_thumb to 12.jpg, 1\_main to 12.jpg, 1\_popup to 12.jpg  
Actually named: 1\_thumb.jpg and so on…  
I am using the code from the php help manual

```php

if ($handle = opendir('../media/models/'.$_GET['model_id']."/model_pics")) {
$i=0;
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && $file != substr_count($file, '_main.jpg') && $file != substr_count($file, '_popup.jpg')) {
           $i++;
        }
    }
 echo "&retval=1&imageCount=".$i;
    closedir($handle);
}

```

Image count is retuned as 34 but it should be 12.  
Anyone?  
Thanks
