hackalive Posted June 22, 2010 Share Posted June 22, 2010 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 Quote Link to comment Share on other sites More sharing options...
Alex Posted June 22, 2010 Share Posted June 22, 2010 Use the DirectoryIterator class to loop through the directories. To get the filename for comparison use the DirectoryIterator::getFilename() method, and to get the path of the files that match use the DirectoryIterator::getPathname() method. Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 22, 2010 Author Share Posted June 22, 2010 @AlexWD could you please provide a sample, especially for the loop part Quote Link to comment Share on other sites More sharing options...
Alex Posted June 22, 2010 Share Posted June 22, 2010 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"; } } Quote Link to comment Share on other sites More sharing options...
hackalive Posted June 22, 2010 Author Share Posted June 22, 2010 appreciated Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.