Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - read text file - but starting at a specific point (not the very first character of the very first line)

Reply
 
Old 07-14-2009   #1 (permalink)
Cary Shultz


 
 

read text file - but starting at a specific point (not the very first character of the very first line)

Good afternoon!

Okay - hopefully a simple solution to this seemingly simple question (but
above my 'skill set').

We have a bunch of text files - plain, vanilla, everyday text files. There
is a specific 'phrase' that shows up (not ever in the same place twice).

What we want to do is to (a) find that phrase and (b) start reading the text
file from that point on.

And, the phrase (Executive Summary) is not necessarily going to be used 15
times in every text file. It *should* appear just once. But, to mitigate
any issues, I would like to start reading the text file at the first
instance of the phrase.

Thanks all!

Cary


My System SpecsSystem Spec
Old 07-14-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: read text file - but starting at a specific point (not the very first character of the very first line)

Cary Shultz wrote:
Quote:

> Okay - hopefully a simple solution to this seemingly simple question (but
> above my 'skill set').
>
> We have a bunch of text files - plain, vanilla, everyday text files.
> There is a specific 'phrase' that shows up (not ever in the same place
> twice).
>
> What we want to do is to (a) find that phrase and (b) start reading the
> text file from that point on.
>
> And, the phrase (Executive Summary) is not necessarily going to be used 15
> times in every text file. It *should* appear just once. But, to mitigate
> any issues, I would like to start reading the text file at the first
> instance of the phrase.
You can use the FileSystemObject to read the contents of the file, and the
InStr function to search for the phrase. You can either read the entire file
at once (using the ReadAll method of the file object), or read one line at a
time (using the ReadLine method). I think you need to read one line at a
time until you find the phrase. Once the phrase is found, process all
subsequent lines. In brief:
=========
Option Explicit

Dim strFile, objFile, strLine, objFSO, strPhrase, blnFound

Const ForReading = 1

strPhrase = "Executive Summary"
strFile = "c:\Scripts\Report.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

blnFound = False
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If (blnFound = True) Then
' Process subsequent lines as desired.
End If
If (InStr(strLine, strPhrase) > 0) Then
' Phrase found.
blnFound = True
End If
Loop
objFile.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to read the LAST NON-BLANK line from a text file? VB Script
Read a line from a text file, without loading the entire file inmemory PowerShell
Howto: Add lines of text from a specific point in a text file.. VB Script
The next line in a text file PowerShell
How do I read a text file and sort text by fixed positions? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46