Better exception safety in scan_for_matching_filenames.
More robust to malformed patterns.