b0w3rb0w3r
b0w3rb0w3r

Reputation: 937

filename string search using fnmatch()

Assuming I have a file on my directory called table.pdf and i'm trying to make a search using the string table as a search criteria. I have tried to do this using fnmatch() with table as my $pattern but this doesn;t return a match whereas using table.pdf as the $pattern returns a match. Example

$table = 'table';
$table_2 = 'table.pdf';
if (fnmatch($table, $pdf)){
// No Match found
}
if (fnmatch($table_2, $pdf)){
// Match Found
}

How do I fix this??

Upvotes: 1

Views: 237

Answers (1)

Jonathan
Jonathan

Reputation: 2877

try this.

$table = 'table*';
$table_2 = 'table.pdf';
if (fnmatch($table, $pdf)){
// No Match found
}
if (fnmatch($table_2, $pdf)){
// Match Found
}

Upvotes: 2

Related Questions