用VBS将一篇txt后缀的内容保存为html格式
程序员文章站
2022-08-27 16:49: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格式,并且有换行效果。
复制代码 代码如下:
'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格式,并且有换行效果。