Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CScript and VBS to Remove Line Breaks from Text File

I have a batch file running which spits out a text/html file. The batch file is causing some line breaks in the text file, which do not translate very well in opening the file in an email. I have been trying to read up on CScript to create a vbs script that can read the text file and strip out the line breaks but have had no luck. Any advice?

like image 863
sfreelander Avatar asked Mar 10 '10 21:03

sfreelander


1 Answers

Not sure how you'd prefer to do it, but this script takes a filename as an argument and writes the results to the same file.

Const ForReading = 1, ForWriting = 2
Dim fs, txt, contents

Set fs = CreateObject("Scripting.FileSystemObject")
Set txt = fs.OpenTextFile(WScript.Arguments(0), ForReading)
contents = txt.ReadAll
txt.Close

contents = Replace(contents, vbCr, "")
contents = Replace(contents, vbLf, "")

Set txt = fs.OpenTextFile(WScript.Arguments(0), ForWriting)
txt.Write contents
txt.Close
like image 165
Tmdean Avatar answered Sep 23 '22 02:09

Tmdean