Thread: File Counter
View Single Post
  #5 (permalink)  
Old 10-22-2008, 09:07 PM
ishkey's Avatar
ishkey ishkey is offline
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,776
ishkey will become famous soon enough
Default

Give this a try.

<?php
$total_mp3_file=count(glob("*.mp3"));
echo "Currently Shuffling ".$total_mp3_file "Songs";
?>
The above example will take from the current directory. To search a specific directory you can use the following. (changes the first line)
To list number of mp3 on a particular directory you can use something like this.
<?php
$total_mp3 = count(glob("/path/to/mp3/{*.mp3}", GLOB_BRACE));
?>

************************************************** **********************
to simply get a count of files in a given directory

<?php
//get path of directory containing this script
$dir = $_SERVER['DOCUMENT_ROOT'].dirname($PHP_SELF);
//open a handle to the directory
$handle = opendir($dir);
//intitialize counter
$count = 0;
//loop through the directory
while (false !== ($file = readdir($handle))) {
//evaluate each entry, removing the . & .. entries
if (is_file($file) && $file !== '.' && $file !== '..') {
$count++;
}
}
echo $count;
?>
or if you prefer, assign the $file variable to an array in the loop:
if...{
$files[$count] = $file;
$count++;
}
then you can return either $count or count($files) to get your number of files.
__________________

Consultant - Programmer - WebMaster
cleandeck - lawn mower undercoating
wilmargraphite - graphite lubricants
Reply With Quote