VBSはGB 2312、UTF-8、Unicode、BIG 5符号化変換ツールを実現します。
echoのデモンストレーション「ABCDE&!@啯莑莑()%」abcdeテスト!>」処理前.txt“GB 2 Ue.vbs”処理前.txt“”処理後.txt“Ue 2 U 8 vbs”処理後.txt“U 82 GB.vbs”処理後.txt“GB 2 U 8 vbs”処理後.txt“U 82 U.vbs”処理後.txt“Ue 2 GB.vbs”処理後も同じ符号化されています。下の中の具体的なコードを使ってください。
' *==============================================================================*
' * CMD GB2312,UTF-8,Unicode,BIG5... 、 *
' * CodeChange.vbs BY: yongfa365
' * GB2Ue.vbs BY: fastslz
' *==============================================================================*
aCode = "GB2312"
bCode = "Unicode"
Show = " "&aCode&" "&bCode&" , ! "
Usage1 = " 1:GB2Ue.vbs [ ][ ][ ] ( )"
Usage2 = " 2:GB2Ue.vbs [ ][ ][ ] [ ][ ][ ] /Y"
Usage3 = " , /Y ! "
Usage4 = " 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 " , 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+"” ==> “"+Getfile+"” "&vbCrLf&" , ?“"+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&" ! ",vbInformation," "
WScript.Quit
end if
slz.Close
set slz = Nothing
End Function
パッケージのダウンロード先。