Page 1 of 1

File Counter!

Posted: Mon Sep 27, 2004 11:44 am
by Joe
Is it possible to count the number of files in a directory using php?.

Regards


Joe 8)

Posted: Mon Sep 27, 2004 11:52 am
by feyd
open the directory, get the file list, count them :P
[php_man]opendir[/php_man]()

Posted: Mon Sep 27, 2004 11:57 am
by Joe
Well feyd that is exactly what I was thinking but the problem is im not to sure on how to count them. I thought of a loop but I was getting nowhere.

Posted: Mon Sep 27, 2004 11:59 am
by feyd
post the code you were trying.

Posted: Mon Sep 27, 2004 12:02 pm
by Joe
To be honest I no longer have it and im not to sure on what I done. I am positive I used a for() loop though. Im sure thats enough for you to know about what I did?.

Regards


Joe 8)

Posted: Mon Sep 27, 2004 12:08 pm
by feyd
if using the opendir method, we most often use a while loop.
each filename returned gets the starting path added to it, as readdir only returns names. This path is then checked to see if it's a file, which will increment a counter or add it to an array.. otherwise, it ignores the path. If an array is used, after the directory is processed, you can use [php_man]sizeof[/php_man]() or [php_man]count[/php_man]() to determine how many elements are in the array (number of files in this case)

Posted: Mon Sep 27, 2004 12:12 pm
by Joe
Ah ha, im sure I know where you are coming from. I will starting working on a work around immediately. Thanks feyd.

Posted: Mon Sep 27, 2004 12:58 pm
by Joe
OK Problem solved. Thanks for the help. count() done exactly what I required.