OK, this code searches recursively from a given starting point all the directories and subdirectories.. I use it for finding and deleting .bak files that I have forgotton to delete.
You would have to tweak it but at least it gets over the recursive stuff which is a pain..
PHP Code:
<?
if($input){
function GetDirArray($sPath,$del) { global $num_bak, $fileval;
$fileval="bak";//CHANGE THIS TO SHTML OR WHATEVER//
$handle=opendir($sPath);
while ($file = readdir($handle))
{
$retVal[count($retVal)] = $file;
}
closedir($handle); sort($retVal);
while (list($key, $val) = each($retVal)) {
if ($val != "." && $val != "..") {
$path = str_replace("//","/",$sPath."/".$val);
//THIS BIT DODGILY CHECKS IF THERE IS A FILE *.BAK AND DELETES IT//
if(substr($path,-3,3)==$fileval)
{
echo $path;
if($del){
//PUT YOUR CODE HERE//
$path = str_replace("//","/",$sPath."/".$val);//unlink($path);
//END HERE!//
}
$num_bak++;
if($sPath!=$oldpath)
{
echo "<br><b>$sPath</b><br>";
$oldpath=$sPath;
}
echo "$path <br>";
}
if (is_dir($sPath."/".$val))
{
GetDirArray($sPath."/".$val."/",$del);
}
}
}
}
GetDirArray($input,$del);
if($num_bak)
{
echo "<h3>Total $num_bak .$fileval files</h3>";
echo "<a href=\"$PHP_SELF?del=1&input=$input\"><h4>Delete *.$fileval files</h4></a>";
}else{
echo "<h4>There are no .$fileval files to delete</h4>";
}
echo "<br><a href=\"$PHP_SELF\">back</a>";
}else{//if input//
?>
<form name="bella" method="post" action="<? echo $PHP_SELF;?>">
Directory to scan for <?=$fileval;?> files:<input type="text" name="input">
<input type="submit" name="submit" value="go">
</form>
<?}?>
(Note the path to enter directories is relative to $DOCUMENT_ROOT)
So in the //PUT YOUR CODE HERE BIT// , you should perfom any operations you want on the file (which will be called $path).., this script lists the files that will be affected before actually doing anything & I have commented out the unlink()!!!! 
hope its useful in some way? ,
PS I scan my whole C:\ drive with this script and have yet to time out, but you can set the timeout value runtime if you run into problems.
Bookmarks