robertazo
(Just in Town)
2012-01-09 08:36 AM
reading from text files

Hello,

I'm rather new to vbscript and it would be very much appreciated if one of you could help me out. I have the following problem:
Basically I have some log files (from robocopy) and I want to search inside of those log files for a certain word.
I've done that using the FileSystemObject what works fine but in my output, each time the word was found in a line it's being echoed out. I just want to have an output telling me only one time if the word has been found or not, even if the word I'm searching for exists many times within the log file.
Also it would be great if I could additionally echo out the name of the log files containing the world I'm searching for.

Thank you very much for your help!


Mart
(KiX Supporter)
2012-01-09 09:18 AM
Re: reading from text files

If you are looking for a vbscript solution then you are on the wrong site because this forum is about kixtart and not vbs.

In kix this is simple. Just open the file, read one line, check the line, read the next line and close the file at the end. See below for an example.

 Code:
Break on

$rc = Open(1, "D:\somefile.txt", 2)

$line = ReadLine(1)

While @ERROR = 0
	If InStr($line, "wordtofind")
		$found = "yes"
	EndIf
	$line = ReadLine(1)
Loop

$rc = Close(1)

If $found = "yes"
	? "Found the requested word in one or more lines."
Else
	? "Did not find the requested word in one or more lines."
EndIf

Sleep 5


robertazo
(Just in Town)
2012-01-09 09:39 AM
Re: reading from text files

Hi Mart,

thanks for that, my fault. Appreciated your help!

Bye!