Reputation: 9541
I am new to RegEx. Can anyone tell me if it's possible to determine if a file name has a specific word in it (like email or games).
And is RegEx the best way to find out? If not what is the best (simplist) way to do this?
Any code samples would be appreciated.
Regards
Upvotes: 2
Views: 515
Reputation: 9541
This is the code I used for finding out if a file name has a specific word in it.
Set objRE = New RegExp
objRE.Global = True
objRE.IgnoreCase = False
objRE.Pattern = WScript.Arguments(0)
For Each objFile In colFiles
bMatch = objRE.Test(objFile.Name)
If bMatch Then
WScript.Echo objFile.Name
objFile.Delete
End If
Next
Upvotes: 0
Reputation: 25435
No regex isn't the best way. Use InStr
like below
Dim str, check
str = "filename.txt"
check = "file"
If InStr(1, str, check) > 0 Then
'Contains
Else
'Does not contain
End If
Hope this helps.
Upvotes: 6