Jump to content

Find files


hackalive

Recommended Posts

Hi, I need some code that searches all folders in a folder tree for specific file names (eg my.php).

 

I need to be able to echo the file name and full url (eg admin/my.php or just admin) in other worrds I need the folder locations of each copy of that file

 

Anyone have any ideas?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/205545-find-files/
Share on other sites

If you want it to search all subdirectories recursively you'll need to use the RecursiveDirectoryIterator. Here's an example:

 

$it = new RecursiveDirectoryIterator('path/to/dir');
foreach(new RecursiveIteratorIterator($it) as $path) {
if(pathinfo($path, PATHINFO_BASENAME) == 'my.php') {
	echo $path . "<br />\n";
}
}

Link to comment
https://forums.phpfreaks.com/topic/205545-find-files/#findComment-1075555
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.