VBScript: rTrim every line of a text file

Home Forums Scripting Windows Script Host VBScript: rTrim every line of a text file

This topic contains 0 replies, has 1 voice, and was last updated by  CaTBuS 10 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts

  • CaTBuS
    Member
    #167422

    As part of another script, I have the need to clean up all trailing spaces from all lines of a text file (rTrim). Below is what I have come up with and it works a treat but I’m sure there must be a better more efficient way to do it. Any ideas?

    Code:
    Option Explicit

    Const ForReading = 1
    Const ForWriting = 2
    Const Open_as_Unicode = True

    Dim objFSO, objFile
    Dim strFolder, strFile, strNewLine, strFile, strLine

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)

    strFolder = “C:Files”
    strFile = “File.txt”
    strFile = strFolder & strFile

    Set objTNS = objFSO.OpenTextFile(strFile, ForReading)

    Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    strLine = rTrim(strLine)
    strNewLine = strNewLine & strLine & vbCrlf
    Loop
    objFile.Close

    Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
    objFile.Write strNewLine
    objFile.Close

    WScript.Quit

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.