CScript 和 VBS 从文本文件中删除换行符 [英] CScript and VBS to Remove Line Breaks from Text File

查看:39
本文介绍了CScript 和 VBS 从文本文件中删除换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件正在运行,它会输出一个文本/html 文件.批处理文件导致文本文件中出现一些换行符,这在电子邮件中打开文件时无法很好地转换.我一直在尝试阅读 CScript 以创建一个可以读取文本文件并去除换行符的 vbs 脚本,但没有成功.有什么建议吗?

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?

推荐答案

不确定您更喜欢怎样做,但此脚本将文件名作为参数并将结果写入同一文件.

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

这篇关于CScript 和 VBS 从文本文件中删除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆