Hi all,

I've been trying to grab some stuff from a "small" text file and dump it in
an other textfile, but up till no luck!
The problem is that it needs to do a search (for the string) and grab the
data after the "="

What I would like to grab is the "SMTPRcvd" count, the "SMTPSent" count and
the "POPSessionsW" count (for now)

Any sugestions (code) how I could do this with a small vbs script?

This is how part of the file looks like:

[Startup]
SMTPRcvd=1232
SMTPSent=707
DomainPOP=0
MultiPOP=3785
POPSessions=142247
IMAPSessions=18
RAWMessages=2871
SMTP=Yes
POP=Yes
IMAP=Yes
RAWMessagesY=1
RAWMessagesW=107
POPSessionsY=233
POPSessionsW=6803
MultiPOPY=1
MultiPOPW=48
SMTPRcvdY=0
SMTPRcvdW=44
SMTPSentY=0
SMTPSentW=15



Thank you,
Noel.

Re: Grab some data from a txt file with vbs. by Steve

Steve
Thu Sep 18 07:02:45 CDT 2003

Noël wrote:
> Hi all,
>
> I've been trying to grab some stuff from a "small" text file and dump it in
> an other textfile, but up till no luck!
> The problem is that it needs to do a search (for the string) and grab the
> data after the "="
>
> What I would like to grab is the "SMTPRcvd" count, the "SMTPSent" count and
> the "POPSessionsW" count (for now)
>
> Any sugestions (code) how I could do this with a small vbs script?
>
> This is how part of the file looks like:
>
> [Startup]
> SMTPRcvd=1232
> SMTPSent=707
> DomainPOP=0
> MultiPOP=3785
> POPSessions=142247
> IMAPSessions=18
> RAWMessages=2871
> SMTP=Yes
> POP=Yes
> IMAP=Yes
> RAWMessagesY=1
> RAWMessagesW=107
> POPSessionsY=233
> POPSessionsW=6803
> MultiPOPY=1
> MultiPOPW=48
> SMTPRcvdY=0
> SMTPRcvdW=44
> SMTPSentY=0
> SMTPSentW=15

Google:
http://www.google.ca/groups?q=read+ini-file+group%3Amicrosoft.public.scripting.vbscript

--
Steve

If mankind minus one were of one opinion, then mankind is no more justified in
silencing the one than the one--if he had the power--would be justified in
silencing mankind. -John Stuart Mill



Re: Grab some data from a txt file with vbs. by Noël

Noël
Thu Sep 18 07:10:22 CDT 2003


"Steve Fulton" <cerberus40@hotmail.com> wrote in message
news:%23crQezdfDHA.3284@tk2msftngp13.phx.gbl...
| Noël wrote:
| > Hi all,
| >
| > I've been trying to grab some stuff from a "small" text file and dump it
in
| > an other textfile, but up till no luck!
| > The problem is that it needs to do a search (for the string) and grab
the
| > data after the "="
| >
| > What I would like to grab is the "SMTPRcvd" count, the "SMTPSent" count
and
| > the "POPSessionsW" count (for now)
| >
| > Any sugestions (code) how I could do this with a small vbs script?
| >
| > This is how part of the file looks like:
| >
| > [Startup]
| > SMTPRcvd=1232
| > SMTPSent=707
| > DomainPOP=0
| > MultiPOP=3785
| > POPSessions=142247
| > IMAPSessions=18
| > RAWMessages=2871
| > SMTP=Yes
| > POP=Yes
| > IMAP=Yes
| > RAWMessagesY=1
| > RAWMessagesW=107
| > POPSessionsY=233
| > POPSessionsW=6803
| > MultiPOPY=1
| > MultiPOPW=48
| > SMTPRcvdY=0
| > SMTPRcvdW=44
| > SMTPSentY=0
| > SMTPSentW=15
|
| Google:
|
http://www.google.ca/groups?q=read+ini-file+group%3Amicrosoft.public.scripting.vbscript
|
| --
| Steve


Thanks Steve,

Stupid of me not to try google 1st! My apology for this.

Noel.



Re: Grab some data from a txt file with vbs. by andersons

andersons
Thu Sep 18 14:51:56 CDT 2003

"Noël" <n03l@hotmail.com> wrote in message news:<#hlZX2dfDHA.2328@TK2MSFTNGP09.phx.gbl>...
> "Steve Fulton" <cerberus40@hotmail.com> wrote in message
> news:%23crQezdfDHA.3284@tk2msftngp13.phx.gbl...
> | Noël wrote:
> | > Hi all,
> | >
> | > I've been trying to grab some stuff from a "small" text file and dump it
> in
> | > an other textfile, but up till no luck!
> | > The problem is that it needs to do a search (for the string) and grab
> the
> | > data after the "="
> | >
> | > What I would like to grab is the "SMTPRcvd" count, the "SMTPSent" count
> and
> | > the "POPSessionsW" count (for now)
> | >
> | > Any sugestions (code) how I could do this with a small vbs script?
> | >
> | > This is how part of the file looks like:
> | >
> | > [Startup]
> | > SMTPRcvd=1232
> | > SMTPSent=707
> | > DomainPOP=0
> | > MultiPOP=3785
> | > POPSessions=142247
> | > IMAPSessions=18
> | > RAWMessages=2871
> | > SMTP=Yes
> | > POP=Yes
> | > IMAP=Yes
> | > RAWMessagesY=1
> | > RAWMessagesW=107
> | > POPSessionsY=233
> | > POPSessionsW=6803
> | > MultiPOPY=1
> | > MultiPOPW=48
> | > SMTPRcvdY=0
> | > SMTPRcvdW=44
> | > SMTPSentY=0
> | > SMTPSentW=15
> |
> | Google:
> |
> http://www.google.ca/groups?q=read+ini-file+group%3Amicrosoft.public.scripting.vbscript
> |
> | --
> | Steve
>
>
> Thanks Steve,
>
> Stupid of me not to try google 1st! My apology for this.
>
> Noel.

Something like this...

Const ForReading = 1
Const ForAppending = 8

Set fso = CreateObject("Scripting.FilesystemObject")
Set file = fso.OpenTextFile("C:\temp\datafile.txt", ForReading, False)
Set nfile = fso.OpenTextFile("C:\temp\newfile.txt", ForAppending, True)

do while file.AtEndOfStream = False
result = file.Readline
if Instr(result, "SMTPRcvd") > 0 then
CP = Instr(result, "=")
SL = Len(result)
CD = Right(Left(result, SL), SL - CP)
nfile.Writeline("SMTPRcvd = "&CD)
endif
if Instr(result, "SMTPSent") > 0 then
CP = Instr(result, "=")
SL = Len(result)
CD = Right(Left(result, SL), SL - CP)
nfile.Writeline("SMTPSent = "&CD)
endif
if Instr(result, "POPSessionsW") > 0 then
CP = Instr(result, "=")
SL = Len(result)
CD = Right(Left(result, SL), SL - CP)
nfile.Writeline("POPSessionsW = "&CD)
endif
loop

file.close
nfile.close

Crude... but should work.

Steve

Re: Grab some data from a txt file with vbs. by Noël

Noël
Thu Sep 18 15:20:41 CDT 2003


"Stephen Anderson" <andersons@canada.com> wrote in message
news:ade4599c.0309181151.2aa947c5@posting.google.com...
| "Noël" <n03l@hotmail.com> wrote in message
news:<#hlZX2dfDHA.2328@TK2MSFTNGP09.phx.gbl>...
| > "Steve Fulton" <cerberus40@hotmail.com> wrote in message
| > news:%23crQezdfDHA.3284@tk2msftngp13.phx.gbl...
| > | Noël wrote:
| > | > Hi all,
| > | >
| > | > I've been trying to grab some stuff from a "small" text file and
dump it
| > in
| > | > an other textfile, but up till no luck!
| > | > The problem is that it needs to do a search (for the string) and
grab
| > the
| > | > data after the "="
| > | >
| > | > What I would like to grab is the "SMTPRcvd" count, the "SMTPSent"
count
| > and
| > | > the "POPSessionsW" count (for now)
| > | >
| > | > Any sugestions (code) how I could do this with a small vbs script?
| > | >
| > | > This is how part of the file looks like:
| > | >
| > | > [Startup]
| > | > SMTPRcvd=1232
| > | > SMTPSent=707
| > | > DomainPOP=0
| > | > MultiPOP=3785
| > | > POPSessions=142247
| > | > IMAPSessions=18
| > | > RAWMessages=2871
| > | > SMTP=Yes
| > | > POP=Yes
| > | > IMAP=Yes
| > | > RAWMessagesY=1
| > | > RAWMessagesW=107
| > | > POPSessionsY=233
| > | > POPSessionsW=6803
| > | > MultiPOPY=1
| > | > MultiPOPW=48
| > | > SMTPRcvdY=0
| > | > SMTPRcvdW=44
| > | > SMTPSentY=0
| > | > SMTPSentW=15
| > |
| > | Google:
| > |
| >
http://www.google.ca/groups?q=read+ini-file+group%3Amicrosoft.public.scripting.vbscript
| > |
| > | --
| > | Steve
| >
| >
| > Thanks Steve,
| >
| > Stupid of me not to try google 1st! My apology for this.
| >
| > Noel.
|
| Something like this...
|
| Const ForReading = 1
| Const ForAppending = 8
|
| Set fso = CreateObject("Scripting.FilesystemObject")
| Set file = fso.OpenTextFile("C:\temp\datafile.txt", ForReading, False)
| Set nfile = fso.OpenTextFile("C:\temp\newfile.txt", ForAppending, True)
|
| do while file.AtEndOfStream = False
| result = file.Readline
| if Instr(result, "SMTPRcvd") > 0 then
| CP = Instr(result, "=")
| SL = Len(result)
| CD = Right(Left(result, SL), SL - CP)
| nfile.Writeline("SMTPRcvd = "&CD)
| endif
| if Instr(result, "SMTPSent") > 0 then
| CP = Instr(result, "=")
| SL = Len(result)
| CD = Right(Left(result, SL), SL - CP)
| nfile.Writeline("SMTPSent = "&CD)
| endif
| if Instr(result, "POPSessionsW") > 0 then
| CP = Instr(result, "=")
| SL = Len(result)
| CD = Right(Left(result, SL), SL - CP)
| nfile.Writeline("POPSessionsW = "&CD)
| endif
| loop
|
| file.close
| nfile.close
|
| Crude... but should work.
|
| Steve


Thanks Steve,

This how I did it. (even cruder I think).
Please note that I have no clue about VBS! (It's also not saving the data
yet!)

Const ForReading = 1

iniFile = "C:\temp\datafile.txt
sectionName = "[Startup]"
keyName = "SMTPSent"
keyName2 = "SMTPRcvd"

bInSection = false

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(iniFile, ForReading)

'read entire file into an array...
'
lines = Split(ts.ReadAll,vbCrLf)
ts.close
For n = 0 to ubound(lines)
if left(lines(n),1) = "[" then
'
'we're entering some section...
'
if bInSection then
'
'no hit possible if we're into a new section...
'
exit for
end if
if instr(lines(n),sectionName) = 1 then
'
'section found
'
bInSection = true
else
bInSection = false
end if
else
'
'look for key only if we're in the right section...
'
if bInSection then
if instr(lines(n),keyName & "=") = 1 then

SMTPRcvd = split(lines(n), "=") ' only the part after the = is what we
want

MsgBox SMTPRcvd(1) & " Messages received"

End If

if instr(lines(n),keyName2 & "=") = 1 then

Count = split(lines(n), "=") ' only the part after the = is what we want

MsgBox SMTPSent(1) & " received"

tot = (SMTPSent(1) / SMTPRcvd(1)) * 100 ' make it %

MsgBox tot

'
'now we can stop looking...
'
exit for
end if
end if
end if
Next

'cleanup...
'
set ts = nothing
set fso = nothing