开发者

VBS and Regular Expressions

开发者 https://www.devze.com 2023-03-07 00:17 出处:网络
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).

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


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消