count specific files

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
lino
Forum Newbie
Posts: 1
Joined: Thu Jan 30, 2003 9:29 am

count specific files

Post by lino »

hi, using the code found at

http://www.evilwalrus.com/viewcode/181.php

what can I add to tell it to only count files with the prefix "bri_" in the directory?

thanks
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

This should work for what ur asking and with simpler code

Code: Select all

print getAllFiles(".");

function getAllFiles ($dir) {
      $d = opendir ("$dir");

      while ($file = readdir ($d)) {
            if (is_dir ($dir."/".$file)) continue;  // EDITED THIS MSG: ADDED THIS LINE
            if ($file == ".." || $file == ".") continue;
            if (preg_match('/^bre_/', $file)) $count++;
      }

      closedir ($d);
      return $count;
}
Post Reply