I have a couple of gif files in a directory with the naming pattern of graph.gif graph001.gif graph002.gif graph003.gif
I want to count total number of graph*.gif files found in that directory.
How could I accomplish this
<?php $count = 0; /* open the directory so PHP can read it */ $targetDir = "/path/to/dir/"; $dirHandle = opendir($targetDir); /* loop through the directories files */ while (($file = readdir($dirHandle)) != false) { if (preg_match("/graph.*\\.gif/",$file)) { $count ++; } } echo($count); ?>