Windows Vista Forums

reading last line of file
  1. #1


    zerbie45 Guest

    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

  2. #2


    James Whitlow Guest

    Re: reading last line of file

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

    > 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

reading last line of file

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete line after reading it on CSV Bishafr PowerShell 4 20 May 2009
Reading SQL Table into Excel and calculating/inserting group line (with VBA)? Claudia d'Amato VB Script 1 11 Jan 2009
Find hidden file, Reading from txt file niva VB Script 3 07 Nov 2008
Reading a text file and retaining line feeds ssg31415926 PowerShell 1 20 Apr 2008
reading a big file line by line to be "out of memory" safe freddy chavez PowerShell 8 02 Aug 2007