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
mikebr
Forum Contributor
Posts: 243 Joined: Sat Sep 28, 2002 7:05 am
Post
by mikebr » Thu Mar 10, 2005 3:20 pm
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
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Mar 10, 2005 3:30 pm
there is no limit that I am aware of.. maybe you should check your error logs?
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Thu Mar 10, 2005 4:42 pm
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 » Fri Mar 11, 2005 2:55 am
Thanks guys. It was a mistake on my part, there was actually only 54 files in the directory.
Mike