网页gb2312转 utf8(保存成后缀是vbs的文件将gb2312文件拖动到该文件即可)
'/*=========================================================================
' * Intro 拖动所有要转换的gb2312编码文件到这个文件上,程序会将它们自动转换为utf-8编码文件
' * FileName GB2312.To.UTF-8.vbs
' * Author yongfa365
' * Version v1.0
' * Email yongfa365[at]qq.com
' * LastModify 2007-10-04 10:42:53
' *==========================================================================*/
Set objArgs = WScript.Arguments
If objArgs.Count>0 Then
If MsgBox ("本程序仅支持GB2312到UTF-8的转换"&vbCrLf&"如果您所拖动的文件里有别的格式的文件请点“取消”", vbOKCancel + vbExclamation + vbDefaultButton2, "郑重提醒!!!") = vbOK Then
For I = 0 To objArgs.Count - 1
FileUrl = objArgs(I)
Call WriteToFile(FileUrl, ReadFile(FileUrl, "gb2312"), "utf-8")
Next
End If
Else
MsgBox "请将您要转换的“gb2312文件”拖到这个文件上"&vbCrLf&"程序会将它们自动转换为utf-8文件", vbInformation, "柳永法温馨提示:"
End If
'-------------------------------------------------
'函数名称:ReadFile
'作用:利用AdoDb.Stream对象来读取各种格式的文本文件
'----------------------------------------------------
Function ReadFile(FileUrl, CharSet)
Dim Str
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.loadfromfile FileUrl
Str = stm.readtext
stm.Close
Set stm = Nothing
ReadFile = Str
End Function
'-------------------------------------------------
'函数名称:WriteToFile
'作用:利用AdoDb.Stream对象来写入各种格式的文本文件
'参数:FileUrl-文件相对路径;Str-文件内容;CharSet-编码格式(utf-8,gb2312.....)
'----------------------------------------------------
Function WriteToFile (FileUrl, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile FileUrl, 2
stm.flush
stm.Close
Set stm = Nothing
End Function
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fuyangchang/archive/2008/07/27/2720674.aspx