Reputation: 79
I have to find live.php and its path within a directory suppose module and its all sub directories such as user, blog and etc. Search also if sub directory blog contains further sub directories.
I am using a long code to do this job. Any other better and short method.
Upvotes: 1
Views: 152
Reputation: 95161
I think you should look at PHP glob
http://php.net/manual/en/function.glob.php
Example : Search dir/module
and sub directory for live.php
or anything that ends with live.php
glob_recursive('dir/module/*live.php');
Function used : http://www.php.net/manual/en/function.glob.php#106595
if ( ! function_exists('glob_recursive'))
{
function glob_recursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
{
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
}
Upvotes: 2