# Dir file count

**URL:** <https://www.phphelp.com/t/dir-file-count/10325>\
**Category:** Beginners - Learning PHP\
**Created:** [September 13, 2007, 2:03pm UTC](https://www.phphelp.com/t/dir-file-count/10325 "2007-09-13T14:03:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyd34](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@andyd34](https://www.phphelp.com/u/andyd34)\
**Post date:** [September 13, 2007, 2:03pm UTC](https://www.phphelp.com/t/dir-file-count/10325/1 "2007-09-13T14:03:50Z")

</div>

I am trying to get the number of files in a directory.

I have the following code

[php]  
if ($handle = opendir(’…/uploads/0000004/’)) {  
while (false !== ($file = readdir($handle))) {  
if ($file != “.” && $file != “…”) {  
$files = array($file);  
echo “$file  
n”;

```
    }
}
closedir($handle);

```

}  
echo count($files);  
[/php]

but its just returning 1

anyone have any suggestions

---

<div class="post-metadata">

**Author:** ![Q1712](https://www.phphelp.com/letter_avatar_proxy/v4/letter/q/a183cd/32.png) [@Q1712](https://www.phphelp.com/u/Q1712)\
**Post date:** [September 13, 2007, 2:11pm UTC](https://www.phphelp.com/t/dir-file-count/10325/2 "2007-09-13T14:11:56Z")

</div>

[php]$files[] = $file;[/php]

---

<div class="post-metadata">

**Author:** ![andyd34](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@andyd34](https://www.phphelp.com/u/andyd34)\
**Post date:** [September 13, 2007, 2:22pm UTC](https://www.phphelp.com/t/dir-file-count/10325/3 "2007-09-13T14:22:02Z")

</div>

Thanks for that, works ok now

[php]

if ($handle = opendir(’…/uploads/0000004/’)) {  
while (false !== ($file = readdir($handle))) {  
if ($file != “.” && $file != “…”) {  
$files[] = $file;

```
    }
}
closedir($handle);

```

}  
if(count($files) \< 6 ) { echo “More Files”; } else { echo “enough is enough”; }

[/php]

---

<div class="post-metadata">

**Author:** ![andyd34](https://www.phphelp.com/letter_avatar_proxy/v4/letter/a/46a35a/32.png) [@andyd34](https://www.phphelp.com/u/andyd34)\
**Post date:** [September 13, 2007, 2:25pm UTC](https://www.phphelp.com/t/dir-file-count/10325/4 "2007-09-13T14:25:46Z")

</div>

Just a quicky, I tried the scandir function and kept on getting the following error

> [i][b]Call to a member function on a non-object [/b][/i]
