Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regular Expression VBScript Help

9 views
Skip to first unread message

KP

unread,
Jan 17, 2010, 11:12:22 PM1/17/10
to
I am trying to create a script to search every file in a directory.

Each file is an email. I need to delete any files that are sent to an
email address ending in ".com.tw"

Like this:
To: j...@acme.com.tw

I can't get my script to work.

What would be the correct syntax for a regular expression that will
match any line of text that has the To: and the .com.tw in that line
of text?

Here is my script:

dim liner
dim lefter
dim righter
dim objFile
dim objFSO
Const ForReading = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile
where Path = '\\test\\'")
Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each objFile in colFiles
dim objTextFile, objRegExp
dim strStringToSearch

' Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objReadFile = objFSO.OpenTextFile(objFile.Name, 1, false)
Set objTextFile = objFSO.OpenTextFile(objFile.Name, ForReading)
Set objRegExp = New RegExp

objRegExp.IgnoreCase = True
objRegExp.Pattern = "To.com.tw"

strStringToSearch = objTextFile.ReadAll


'if (objRegExp.Test(strStringToSearch)) then
' wscript.echo objFile.Name
'end if

Set Matches = objRegExp.Execute(strStringToSearch)
For Each myMatch in Matches
wscript.echo objFile.Name
' 'wscript.echo myMatch.Value, 0, "Found Match"
Next

Set objRegExp = Nothing 'Clean up!

'objReadFile.close
'wscript.echo contents


Next

'Clean up \ objTextFile.Close
Set objFSO = Nothing
Set objTextFile = Nothing

Al Dunbar

unread,
Jan 18, 2010, 8:24:46 PM1/18/10
to

"KP" <kingpin...@yahoo.com> wrote in message
news:1e0f7d53-f927-402f...@p24g2000yqm.googlegroups.com...


> I am trying to create a script to search every file in a directory.
>
> Each file is an email.

In what format, *.msg, *.rtf, *.txt, other?

> I need to delete any files that are sent to an
> email address ending in ".com.tw"
>
> Like this:
> To: j...@acme.com.tw
>
> I can't get my script to work.

First thing is to open one of the message files in notepad to see if the
string "To: j...@acme.com.tw" actually appears in plain text within the file.

> What would be the correct syntax for a regular expression that will
> match any line of text that has the To: and the .com.tw in that line
> of text?

I'm not sure, but if I forwarded your post to your email address and you
saved it as a text file with the other messages it would be deleted even
though it was not sent to anyone at the com.tw domain.

To achieve what you are looking for might require a different approach to
ensure that textual coincidences do not result in errors. What you have
asked is how to delete messages sent to an address matching ..., whereas
your approach seems to be to find any message with a particular text string
in it.

/Al

0 new messages