Searching for a text string in the cPanel File Manager

Avatar
  • Answered
Can you search for text strings within the files using the search in the top right screen on file manager?
Avatar
JeffMa
Unfortunately, the search box at the top right of the cPanel File Manager is unable to search within files and only locates file or folder names. If you want to search through files in a directory for a string, you could do so with the following PHP script:

<?php // string to search in a filename. $searchString = 'myFile'; // all files in my/dir with the extension // .php $files = glob('my/dir/*.php'); // array populated with files found // containing the search string. $filesFound = array(); // iterate through the files and determine // if the filename contains the search string. foreach($files as $file) { $name = pathinfo($file, PATHINFO_FILENAME); // determines if the search string is in the filename. if(strpos(strtolower($name), strtolower($searchString))) { $filesFound[] = $file; } } // output the results. print_r($filesFound); ?>