lundi 5 décembre 2016

How match with pattern and "like" operator including square brackets [] in vb.net

This method returns true when it shouldn't

pattern = "*[cryptservice@inbox.ru]*"
file = "test.pdf"
    If file Like pattern Then
        MsgBox("like method, file: " & file)
    End If

for every file i put into the var file, i get true in this line:

If file Like pattern Then

the real true should appear at

file = "P0LRBE2RUK[cryptservice@inbox.ru].awes0me"

So, how can I escape the square bracket ([]) for a search Pattern (not regex)

BTW I've a list of pattern from an API (http://ift.tt/1TNHIeF), and i can't use:

For Each file In IO.Directory.GetFiles(path, pattern,IO.SearchOption.AllDirectories)

Because the IO.Directory.GetFiles throw an exception for denied folders

Aucun commentaire:

Enregistrer un commentaire