欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用VBS将一篇txt后缀的内容保存为html格式

程序员文章站 2022-05-14 21:00:15
do.vbs复制代码 代码如下:'by coo_boi if wscript.arguments.count=0 then wscript.quit dim fso,txt...
do.vbs
复制代码 代码如下:

'by coo_boi
if wscript.arguments.count=0 then wscript.quit
dim fso,txt,htm
txt=wscript.arguments(0)
set fso=createobject("scripting.filesystemobject")
set htm=fso.createtextfile(txt&".htm",true)
title=fso.getfile(txt).name
title=left(title,len(title)-4)
msgbox title
htm.writeline "<html>"
htm.writeline "<head>"
htm.writeline "<title>"&title&"</title>"
htm.writeline "</head>"
htm.writeline "<body>"
htm.writeline "<h1 align=center>"&title&"</h1>"
htm.writeline "<hr color=red>"
for each line in split(fso.opentextfile(txt).readall ,vbcrlf)
htm.writeline line&"<br>"
next
htm.writeline "</body>"
htm.writeline "</html>"
htm.close
wscript.echo "将txt转换为html成功"

将上面的代码保存为do.vbs,然后将1.txt托动到do.vbs上。即可将txt的内容生成为html格式,并且有换行效果。