开发者

CScript and VBS to Remove Line Breaks from Text File

开发者 https://www.devze.com 2022-12-23 00:41 出处:网络
I have a batch file running which spits out a text/html file.The batch file is cau开发者_开发知识库sing some line breaks in the text file, which do not translate very well in opening the file in an em

I have a batch file running which spits out a text/html file. The batch file is cau开发者_开发知识库sing 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消