VBS寫的GB2312,UTF-8,Unicode,BIG5編碼轉(zhuǎn)換工具,轉(zhuǎn)換工具下載:GB2Ue.vbs (3.34 kb)
演示
echo "ABCDE &!@#$ ^<>() %% abcde 測試!"> "處理前.txt"
GB2Ue.vbs "處理前.txt" "處理后.txt"
Ue2U8.vbs "處理后.txt"
U82GB.vbs "處理后.txt"
GB2U8.vbs "處理后.txt"
U82Ue.vbs "處理后.txt"
Ue2GB.vbs "處理后.txt"
@echo 經(jīng)過6次處理 "處理后.txt" 和 "處理前.txt" 仍舊是相同編碼
如果不知道文件的原始編碼,請(qǐng)使用
下面里面里面具體代碼:
代碼如下:
' *==============================================================================*
' * CMD 命令行編碼轉(zhuǎn)換工具包括GB2312,UTF-8,Unicode,BIG5...支持拖拽、文件另保存為 *
' * CodeChange.vbs BY: yongfa365
' * GB2Ue.vbs BY: fastslz
' *==============================================================================*
aCode = "GB2312"
bCode = "Unicode"
Show = "本腳本僅支持"&aCode&"到"&bCode&"的轉(zhuǎn)換,請(qǐng)拖拽單個(gè)要轉(zhuǎn)換的文件到此文件上! "
Usage1 = "語法1:GB2Ue.vbs [驅(qū)動(dòng)器][目錄][文件名] (直接替換原文件模式)"
Usage2 = "語法2:GB2Ue.vbs [驅(qū)動(dòng)器][目錄][文件名] [目標(biāo)驅(qū)動(dòng)器][目錄][新名稱] /Y"
Usage3 = " 如果目標(biāo)新文件已存在,使用/Y參數(shù)后將直接替換而不提示是否改寫! "
Usage4 = "命令行編碼轉(zhuǎn)換工具 BY: fastslz"
Set objArgs=WScript.Arguments
Set fso=CreateObject("Scripting.FileSystemObject")
if objArgs.Count=0 Then
MsgBox Show &vbCrLf&vbCrLf& Usage1 &vbCrLf& Usage2 &vbCrLf& Usage3, vbInformation, Usage4
Wscript.Quit
end if
if not objArgs.Count < 3 Then
Options="/y"
ignoring = StrComp(objArgs(2), Options, vbTextCompare)
if ignoring = 0 Then
Sourcefile=objArgs(0)
Getfile=objArgs(1)
else
MsgBox "文件數(shù)量或參數(shù)太多,拖拽批量處理請(qǐng)用 ANSI2Unicode.vbs ", vbInformation, "程序意外終止"
Wscript.Quit
end if
else
if not objArgs.Count < 2 Then
Sourcefile=objArgs(0)
Getfile=objArgs(1)
if fso.FileExists(objArgs(1)) then
Choice = MsgBox ("待處理文件“"+Sourcefile+"” ==> 目標(biāo)文件“"+Getfile+"” "&vbCrLf&"目標(biāo)文件已存在,是否改寫現(xiàn)有文件?“"+objArgs(1)+"” ",vbQuestion+vbYesNo,"是否改寫")
if Choice = vbYes Then
Getfile=objArgs(1)
else
Wscript.Quit
end if
end if
else
Sourcefile=objArgs(0)
Getfile=objArgs(0)
end if
end if
Call CheckCode (Sourcefile)
Call WriteToFile(Getfile, ReadFile(Sourcefile, aCode), bCode)
Wscript.Quit
Function ReadFile (Sourcefile, CharSet)
Dim Str
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.loadfromfile Sourcefile
Str = stm.readtext
stm.Close
Set stm = Nothing
ReadFile = Str
End Function
Function WriteToFile (Getfile, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile Getfile,2
stm.flush
stm.Close
Set stm = Nothing
End Function
Function CheckCode (Sourcefile)
Dim slz
set slz = CreateObject("Adodb.Stream")
slz.Type = 1
slz.Mode = 3
slz.Open
slz.Position = 0
slz.Loadfromfile Sourcefile
Bin=slz.read(2)
if AscB(MidB(Bin,1,1))=&HEF and AscB(MidB(Bin,2,1))=&HBB Then
Codes="UTF-8"
elseif AscB(MidB(Bin,1,1))=&HFF and AscB(MidB(Bin,2,1))=&HFE Then
Codes="Unicode"
else
Codes="GB2312"
end if
if not aCode = Codes Then
MsgBox "待處理文件 “"&Sourcefile&"”"&vbCrLf&"該文件原始編碼不是"&aCode&",本腳本僅支持"&aCode&"到"&bCode&"的轉(zhuǎn)換! ",vbInformation,"錯(cuò)誤終止"
WScript.Quit
end if
slz.Close
set slz = Nothing
End Function