File count

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
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

File count

Post by icesolid »

How can I count how many files are in a directory excluding "." and ".."?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

glob() and count()
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post 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>";
}
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

<?php 

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

?>
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Just tested it and it works fine for me....?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hawleyjr wrote:Just tested it and it works fine for me....?
icesolid used readdir().
Post Reply