中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
作者:
标题: htm2BAT 上一主题 | 下一主题
chengbiner
初级用户





积分 105
发帖 44
注册 2006-10-5
状态 离线
『楼 主』:  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


2007-3-5 07:29
查看资料  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: