VBScript: rTrim every line of a text file Share on Facebook Post on reddit Tweet on Twitter Share on LinkedIn Home › Forums › Scripting › Windows Script Host › VBScript: rTrim every line of a text file This topic has 0 replies, 1 voice, and was last updated 2 years, 11 months ago by CaTBuS. Viewing 1 post (of 1 total) Author Posts CaTBuSMember Feb 13, 2018 at 8:22 am #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 Author Posts Viewing 1 post (of 1 total) You must be logged in to reply to this topic.