Welcome to WebmasterWorld Guest from 54.226.133.245

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

counting file with filename containing

     
3:31 pm on Mar 24, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 17, 2006
posts:137
votes: 0


i have a folder called "datafolder" and i would like to see if there are files in there that begin with the name "2010-002" and if so how many files there are that begin with that convention.

can any advise me on how i can achieve this?

thanks
3:41 pm on Mar 24, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 6, 2008
posts:2011
votes: 0


Run this in the folder.

<?php
$count = 0;
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if(substr_count($file, '2010-002') >= 1)
{$count++;}
}
}
closedir($handle);
}
echo "Count: ".$count;
?>