How to find a file in folders with sub name of the file means the file need to be searched is not fully named but it is a part of the name for example I want to search the file namely 'hello_world_123.png'. I did not enter full name of the file but one or some words only, for example the 'world_' is my input but the code should search the full name of file.
In short the searching may work like operating system's search in file explorer or file manager.
My code as below but I am stuck with matching the name of file in if condition.
$file_name_ = 'recursive-1.php';
$dir = new RecursiveDirectoryIterator( $folder_path, RecursiveDirectoryIterator::SKIP_DOTS);
$it = new RecursiveIteratorIterator($dir);
foreach($it as $file) {
$file_info = pathinfo($file);
$patt = '/^(\w+)\.+('.$file_name_.')\.+(\w+)*$/';
$result = preg_match($patt,strtolower( $file_info['basename'] ),$match );
if ( $result ) {
echo 'File found';
} else {
echo 'File not found';
}
}