Count Files on Directory?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gertrudis
Forum Newbie
Posts: 14
Joined: Wed Jan 27, 2010 8:15 pm

Count Files on Directory?

Post by gertrudis »

Hi all.
I need to know how can i count files using the first 3 beginning letter of file name:

this is the code i'm using, it list and sort the files on the directory bu I need to count it:

for ($count=0;$count<count($filelist);$count++)
{
$filename=$filelist[$count];
if (!is_dir($filename))
$nombase=(basename($filename));
printf (substr("$nombase", 0, 2));
}
All files start with two number or letter example:
Files Total
10 35
13 55
15 25
16 29

Thank in advance
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Count Files on Directory?

Post by requinix »

Here's something to start you off:

Code: Select all

$count = array();
Since that's not much I'll give you a bit more:

Code: Select all

if (!isset($count[$prefix])) $count[$prefix] = 1; else $count[$prefix]++;
gertrudis
Forum Newbie
Posts: 14
Joined: Wed Jan 27, 2010 8:15 pm

Re: Count Files on Directory?

Post by gertrudis »

Thanks a lot :crazy:
Post Reply