Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET

VBScript: rTrim every line of a text file

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

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.

Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: