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
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Files

Post by uberpolak »

Does anybody know of a function that would get the number of files in a given directory? I've been unable to find such a function.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

i don't believe there is one. try this though:

Code: Select all

function fileCount($dir) {
  $dirHandle = opendir($dir);
  $fileCount = 0;
  while (($file = readdir($dirHandle)) !== FALSE) {
    $fileCount++;
  }
  return $fileCount;
}
note: not tested
Post Reply