0

Currently I have these files in a folder:

Is it possible to make list all files that start with server_log and display those filenames on the screen?

Kermit
  • 33,827
  • 13
  • 85
  • 121
Ghermans41
  • 51
  • 1
  • 1
  • 8

2 Answers2

5

Use glob(). The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.

$ListFile = glob("/path/server_log_*");
print_r($ListFile);
Simone Nigro
  • 4,717
  • 2
  • 37
  • 72
1

Yes, take a look at this answer.

$dir ="your path here";

$filetoread ="server_log";
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
           if (strpos($file,$filetoread) !== false)
            echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
        }
        closedir($dh);
    }
}
Community
  • 1
  • 1
cgross
  • 1,932
  • 2
  • 15
  • 20