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 CaTBuS 1 year, 9 months ago.

Viewing 1 post (of 1 total)
  • Author
  • CaTBuS

    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?

    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

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


Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.