『楼 主』:
htm2BAT
完全盗用skyearth 兄的vbs2bat代码,请兄见量!不过我感觉不只可以转换vbs,
还可以转换txt、htm、bat、asp……
保存为vbs脚本!
Dim I, htmname, BatName, DesName
For I = 0 To WScript.Arguments.Count - 1
If I = 0 Then htmname = WScript.Arguments(I)
If I = 1 Then BatName = WScript.Arguments(I)
If I = 2 Then DesName = WScript.Arguments(I)
Next
IF Len(htmname) > 0 Then
Dim fso,f1,r,aryline,strline
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(htmname) then htmname = htmName & ".htm"
IF Len(BatName) = 0 Then
IF Ucase(Right(htmname,4)) = ".htm" Then BatName = Left(htmname,Len(htmname) - 4) & ".BAT"
IF Len(BatName) = 0 Then BatName = htmname & ".BAT"
End IF
IF fso.FileExists(htmname) then
Set f1 = fso.OpenTextFile(htmname,1)
r = f1.ReadAll
f1.Close
'插入ECHO --- >>TEMP.htm
r = replace(r, chr(10),"", 1)
If len(r) > 0 Then
aryline = split(r, chr(13))
IF Len(DesName) = 0 Then DesName = "%TEMP%\_ST0101_.htm"
'IF Len(DesName) = 0 Then DesName = "_ST0101_.htm"
'生成文件头
r = "@ECHO OFF"
for i = lbound(aryline) to ubound(aryline)
strline = trim(aryline(i))
'替换">","<"," &","|"……
strline = replace(strline, ">", "^>", 1)
strline = replace(strline, "<", "^<", 1)
strline = replace(strline, " &", " ^&", 1)
strline = replace(strline, "|", "^|", 1)
strline = replace(strline, "%", "%%", 1)
strline = replace(strline, """", "^""", 1)
strline = replace(strline, "!", "^!", 1)
strline = replace(strline, " &&", " &^&", 1)
strline = replace(strline, "(", "^(", 1)
strline = replace(strline, ")", "^)", 1)
strline = LTrimTab(strline)
If Left(strline,1) = "'" or Lcase(Left(strline,4)) = "rem " then strline = ""
'添加BAT生成语句
If Len(strline) > 0 Then
r = r & vbnewline & "ECHO " & strline & " >>temp.htm"
End If
next
'生成文件尾
r = r & vbnewline _
& "cls" & vbnewline _
& "echo 转换成功,欢迎到dos 联盟"& vbnewline _
& "pause>nul"
Set f1 = fso.OpenTextFile(BatName,2,True)
f1.Write r
f1.Close
MsgBox BatName & "转换成功!",64,"htm2BAT"
End If
End IF
End IF
'过滤左边的TAB符
Function LTrimTab(SpecStr)
Dim C, F
For C = 1 to Len(SpecStr)
If Mid(SpecStr,C,1) = chr(9) Then
F = F + 1
Else
If F > 0 Then
LTrimTab = Mid(SpecStr, C)
Else
LTrimTab = SpecStr
End If
Exit Function
End If
Next
End Function
|