Page 1 of 1

File count

Posted: Thu Aug 23, 2007 4:17 pm
by icesolid
How can I count how many files are in a directory excluding "." and ".."?

Posted: Thu Aug 23, 2007 4:26 pm
by John Cartwright
glob() and count()

Posted: Thu Aug 23, 2007 4:40 pm
by icesolid
The code below always produces 1 no matter how many are in the folder.

Code: Select all

$dir = opendir("/home/wiles63/public_html/jobstatus/files/17/");

$file_count = count(readdir($dir));
echo $file_count;

if($file_count == "0") {
    echo "<big><font color=\"#FF0000\"><b>No files have been attached!</b></font></big>";
}

Posted: Thu Aug 23, 2007 4:43 pm
by hawleyjr

Code: Select all

<?php 

echo count( glob( '/home/wiles63/public_html/jobstatus/files/17/*' ) );

?>

Posted: Thu Aug 23, 2007 4:56 pm
by hawleyjr
Just tested it and it works fine for me....?

Posted: Fri Aug 24, 2007 10:11 am
by feyd
hawleyjr wrote:Just tested it and it works fine for me....?
icesolid used readdir().