Is there a readdir() limit?

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
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Is there a readdir() limit?

Post by mikebr »

I have a function for counting files in a directory but it won't seem to count over 54 files, is there a limit to the number of files that you can count in a directory?

the function I use is:

Code: Select all

function count_files_in_dir($theDirectory) {

	if ($adir = @opendir($theDirectory)) {
	$i=0;
		while ($afile = readdir($adir)) {
			if ($afile=="." || $afile=="..") {
			// Don't count them
			} else {
			$i++;
			}
		}//end while
			
		closedir($adir);
	
	}
	
	return $i; 
}

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there is no limit that I am aware of.. maybe you should check your error logs?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Is there a readdir() limit?

Post by Chris Corbyn »

Debug it by making it show what it counts so you can check it's actually counting what you think it is:

Code: Select all

function count_files_in_dir($theDirectory) {

	if ($adir = @opendir($theDirectory)) {
	$i=0;
		while ($afile = readdir($adir)) {
			if ($afile=="." || $afile=="..") {
			// Don't count them
			} else {
			$i++;
			echo $i .'=>'. $afile .'<br>';
			}
		}//end while
			
		closedir($adir);
	
	}
	
	return $i; 
}
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

Thanks guys. It was a mistake on my part, there was actually only 54 files in the directory.

Mike
Post Reply