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 - reading last line of file

Reply
 
Old 10-21-2008   #1 (permalink)
zerbie45


 
 

reading last line of file

hi guys,

I have a text file which I need to read from a vbscript, but I should
only get the last string. does anybody has an example that I could use
to write such script ?

further, the file has two empty strings at the bottom. which is the
best method to deal with this ? should the script read the third line
from the bottom, or is it simpler to get rid of these empty strings ?
an example would be very, very appreciated!

thanks in advance for any help.
zz

My System SpecsSystem Spec
Old 10-21-2008   #2 (permalink)
James Whitlow


 
 

Re: reading last line of file

<zerbie45@xxxxxx> wrote in message
news:dfca51a7-b2f7-451d-a4e3-f4bebcb7ee7f@xxxxxx
Quote:

> hi guys,
>
> I have a text file which I need to read from a vbscript, but I should
> only get the last string. does anybody has an example that I could use
> to write such script ?
>
> further, the file has two empty strings at the bottom. which is the
> best method to deal with this ? should the script read the third line
> from the bottom, or is it simpler to get rid of these empty strings ?
> an example would be very, very appreciated!
If I am understanding your request, I think something like this should
work for you:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit

Dim oFSO, oRegEx, sFileName, sText, oMatches

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.Multiline = True
oRegEx.Global = True

sFileName = "C:\MyFile.txt"

sText = oFSO.OpenTextFile(sFileName, 1).ReadAll
oRegEx.Pattern = "^([^\s]+)$"
Set oMatches = oRegEx.Execute(sText)

MsgBox oMatches(oMatches.Count - 1)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Delete line after reading it on CSV PowerShell
Reading SQL Table into Excel and calculating/inserting group line (with VBA)? VB Script
Find hidden file, Reading from txt file VB Script
Reading a text file and retaining line feeds PowerShell
reading a big file line by line to be "out of memory" safe 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