ho risolto con una funzione autoricorsiva:

<?php

if(isset($_POST['find'])&& $_POST['find']!=""){

$find=$_POST['find'];
//vede se ci sono cartelle
$dir = "./files";

function trova($dir, &$find){
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {

$pos = strpos($file, $find);
if($pos===false){}else{echo $dir."/".$file."
";}

if (is_dir($dir."/".$file))
{
trova($dir."/".$file,$find);
}
}
}
closedir($handle);
}
}
trova($dir,$find);

}
?>