Min
Min

Reputation: 11

How to search for file with partial wildcard in VBS

I need to search for filename AM*GQ, where * is sequence eg 344

Can i do this vbs?

Upvotes: 1

Views: 9051

Answers (2)

Tester101
Tester101

Reputation: 8182

Regular Expressions should work.

pattern = "[A][M][0-9]*[G][Q].*"
stringToSearch = "AM432GQ.txt"
MsgBox RegExTest(pattern,stringToSearch)

Function RegExTest(pattern, stringToSearch)
   Dim regEx, Match, Matches   ' Create variable.
   Set regEx = New RegExp   ' Create a regular expression.
   regEx.Pattern = pattern   ' Set pattern.
   regEx.IgnoreCase = True   ' Set case insensitivity.
   regEx.Global = True   ' Set global applicability.
   Set Matches = regEx.Execute(stringToSearch)   ' Execute search.
   For Each Match in Matches   ' Iterate Matches collection.
      RetStr = RetStr & "Match found at position "
      RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
      RetStr = RetStr & Match.Value & "'." & vbCRLF
   Next
   RegExTest = RetStr
End Function

Upvotes: 1

ghostdog74
ghostdog74

Reputation: 343143

you can use instr()

Upvotes: 1

Related Questions