内容显示页
 
类别:服务器+软件 | 浏览(1222) | 2007-10-24 11:50:26

'/*=========================================================================
' * Intro       因为Emeditor识别文本编码的能力比较强,所以用Emeditor打开我们想转换的文件,它都可以正常打开的,打开后我们再改变这个文件的编码,然后保存之
' * FileName    CodeChange.vbee
' * Author      yongfa365
' * Version     v1.0
' * WEB         http://www.yongfa365.com
' * Email       yongfa365[at]qq.com
' * FirstWrite  http://www.yongfa365.com/Item/CodeChange.vbee.html
' * LastModify  2007-10-06 02:42:01
' *==========================================================================*/

Set mainMenu=CreatePopupMenu
mainMenu.Add "功能:编码转换",0
mainMenu.Add "", 0, eeMenuSeparator 
mainMenu.Add "指定文件夹下所有文件存为指定编码文件",1
mainMenu.Add "", 0, eeMenuSeparator 
mainMenu.Add "当前文档存为gb2312",2
mainMenu.Add "当前文档存为utf-8",3
mainMenu.Add "当前文档存为指定编码文件",4
mainMenu.Add "", 0, eeMenuSeparator 
mainMenu.Add "所有文档存为指定编码文件",5
mainMenu.Add "所有文档存为gb2312",6
mainMenu.Add "所有文档存为utf-8",7
mainMenu.Add "", 0, eeMenuSeparator 
mainMenu.Add "程序说明",100
witchItem=mainMenu.Track
Select Case witchItem
    Case 1
        sPath = prompt("请输入要处理的文件所在的文件夹", "")
        If FolderExits(sPath) = False Then
            alert "输入的文件夹不存在,退出?"
            Quit
        End If
        bSubFolder = confirm("包括子文件夹?")
        sExt = prompt("只处理这些后缀的文件:(为空表示处理所有文件,各后缀以“|”隔开)", "html|htm|asp|php|php4")
        NewCode = prompt("文档编码转换为:(936-->gb2312,65001-->utf-8)", "65001")
        If IsNumeric(NewCode) Then
            Call FilesTree(sPath, bSubFolder)
            Set re = New RegExp
            re.Pattern = "([^|]+\.(" & sExt & "$))"
            re.IgnoreCase = True
            re.Global = True
            Set Matches = re.Execute(AllFiles)
            editor.NewFile
            For Each oMatch In Matches
                editor.OpenFile oMatch.SubMatches(0)
                SaveFile oMatch.SubMatches(0), NewCode
            Next
            Close
        Else
            alert "输入有误,必须输入数字,退出"
            Quit
        End If
    Case 2
        SaveFile document.FullName, 936
    Case 3
        SaveFile document.FullName, 65001
    Case 4
        NewCode = prompt("您要将当前文档编码转换为:(936-->gb2312,65001-->utf-8)", "936|65001")
        If IsNumeric(NewCode) Then
            SaveFile document.FullName, NewCode
        Else
            alert "输入有误,必须输入数字,退出"
            Quit
        End If
    Case 5
        NewCode = prompt("您要将所有文档编码转换为:(936-->gb2312,65001-->utf-8)", "936|65001")
        If IsNumeric(NewCode) Then
            AllDocNum = editor.Documents.Count
            Set NowFile = editor.ActiveDocument
            For i = 0 To AllDocNum
                editor.ExecuteCommandByID 5376 + i
                SaveFile document.FullName, NewCode
            Next
            NowFile.Activate()
        Else
            alert "输入有误,必须输入数字,退出"
            Quit
        End If
    Case 6
        AllDocNum = editor.Documents.Count
        Set NowFile = editor.ActiveDocument
        For i = 0 To AllDocNum
            editor.ExecuteCommandByID 5376 + i
            SaveFile document.FullName, 936
        Next
        NowFile.Activate()
    Case 7
        AllDocNum = editor.Documents.Count
        Set NowFile = editor.ActiveDocument
        For i = 0 To AllDocNum
            editor.ExecuteCommandByID 5376 + i
            SaveFile document.FullName, 65001
        Next
        NowFile.Activate()
    Case 100
        Msg= "柳永法制作,http://www.yongfa365.com"
        Msg=Msg & vbcrlf & "本宏在制作过程中有一块地方用了半天时间才发现问题:"
        Msg=Msg & vbcrlf & "如果您的文档是英文与数字组合没有双字节文字,"
        Msg=Msg & vbcrlf & "并且文档是没有BOM的utf-8格式,那么再次打开这个文档时,"
        Msg=Msg & vbcrlf & "EmEditor还是会把这个文档编码认为是系统默认的文档,"
        Msg=Msg & vbcrlf & "如果是简体中文系统,显示的还是936 gb2312编码,"
        Msg=Msg & vbcrlf & "但他确实是utf-8的,只是这两种编码都可以正常打开这个文件。"


        alert(Msg)
End Select

Sub SaveFile(FileName, CodePage)
    editor.ExecuteCommandByID 4105 'Save As vbCrLf
    document.Encoding = CodePage 'Encoding gb2312-->936 utf-8-->65001 ...
    If CodePage = 65001 Or CodePage = 65005 Or CodePage = 65006 Then document.UnicodeSignature = False 'BOM
    document.Save FileName
End Sub

Function FolderExits(Folder)
    Set FSO = CreateObject("Scripting.FileSystemObject")
    If FSO.FolderExists(Folder) Then
        FolderExits = True
    Else
        FolderExits = False
    End If
End Function

引用本页地址:http://www.yongfa365.com/item/CodeChange.vbee.html
 
 
相关链接
 
网友评论:
1 午夜客 - 2007-10-26 10:55:46
怎么使用,直接打开EMEDITOR,把这个宏粘贴进去吗?
 
2 yongfa365 - 2007-10-26 12:12:12
研究一下emeditor的宏就知道了
 
3 dead - 2009-5-3 14:07:56
出现这个错误
类型不匹配: 'FilesTree'
38行
 
4 匿名网友 - 2010-1-30 14:45:40
大哥,东西是好东西,正好我今天就用到了!
但是你这里少了个FIlesTree 这个子过程,
在你的博客里面也没有找到 两个参数的 子过程……
可惜我对VBscript不懂啊,看你这个例子,我恁是看了一个VBSript的简介……
不管怎么样,感谢博主分享的这些Emeditor的宏……非常感谢!
 
5 匿名网友 - 2010-2-1 16:33:58
研究完了,现附上我的修改链接
h t t p: / / hi.baidu.com/yuyujulin/blog/item/0242c2187e954bbf4bedbc33.html
如有侵犯版权之处,请打1-1-0!!
 
姓名: 记住我
网址:
邮箱:
内容:
验证码:  验证码图片 看不清? 换张图试试
 
     
 
 
文章分类
 
 
专题(3)
 
.Net + C#(54)
 
 
ASP+VBS(159)
 
 
 
Linux(10)
 
 
 
web 2.0(24)
 
 
 
 
 
心程(66)
 
生活(95)
 
 
     

Power by :柳永法(yongfa365)'Blog  | 京ICP备07011491号  QQ:64049027  E-mail:64049027qq.com yongfa365'CodePlex

转载请注明来源,以便后人及时得到最新、修正、加强版!!!