Page 1 of 1

Is there a readdir() limit?

Posted: Thu Mar 10, 2005 3:20 pm
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]

Posted: Thu Mar 10, 2005 3:30 pm
by feyd
there is no limit that I am aware of.. maybe you should check your error logs?

Re: Is there a readdir() limit?

Posted: Thu Mar 10, 2005 4:42 pm
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; 
}

Posted: Fri Mar 11, 2005 2:55 am
by mikebr
Thanks guys. It was a mistake on my part, there was actually only 54 files in the directory.

Mike