Find files with a pattern in a directory


define('DIR_PATH', 'DIRECTORY PATH');

$filenames = scandir(DIR_PATH);

$pattern = '/^PATTERN/';
$matches = array();
$matches[] = preg_grep($pattern, $filenames);

print_r($matches);

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.