' *==============================================================================*
' * CMD Command Line Encoding Conversion Tool supports GB2312, UTF-8, Unicode, BIG5... with drag-and-drop and save-as functionality *
' * CodeChange.vbs BY: yongfa365 http://www.yongfa365.com 2007-10-04 *
' * GB2Ue.vbs BY: fastslz http://bbs.cn-dos.net 2007-12-03 *
' *==============================================================================*
aCode = "GB2312"
bCode = "Unicode"
Show = "This script only supports conversion from " & aCode & " to " & bCode & ". Please drag a single file to be converted onto this file! "
Usage1 = "Syntax 1: GB2Ue.vbs (Directly replace original file mode)"
Usage2 = "Syntax 2: GB2Ue.vbs /Y"
Usage3 = " If the target new file already exists, using the /Y parameter will directly replace it without prompting! "
Usage4 = "Command Line Encoding Conversion Tool 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 "Too many files or parameters. For batch processing via drag-and-drop, please use ANSI2Unicode.vbs ", vbInformation, "Program Terminated Unexpectedly"
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 ("File to process: “" + Sourcefile + "” ==> Target file: “" + Getfile + "” " & vbCrLf & "Target file already exists. Overwrite existing file? “" + objArgs(1) + "” ", vbQuestion + vbYesNo, "Overwrite?")
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 "File to process: “" & Sourcefile & "”" & vbCrLf & "The original encoding of this file is not " & aCode & ". This script only supports conversion from " & aCode & " to " & bCode & "! ", vbInformation, "Terminated Due to Error"
WScript.Quit
end if
slz.Close
set slz = Nothing
End FunctionDemo
echo "ABCDE &!@#$ ^<>() %% abcde Test!"> "Before Processing.txt"
GB2Ue.vbs "Before Processing.txt" "After Processing.txt" /y
Ue2U8.vbs "After Processing.txt"
U82GB.vbs "After Processing.txt"
GB2U8.vbs "After Processing.txt"
U82Ue.vbs "After Processing.txt"
Ue2GB.vbs "After Processing.txt"
@echo After 6 processing steps, "After Processing.txt" and "Before Processing.txt" still have the same encoding
Encoding Query Tool QueryCode.vbs
http://www.cn-dos.net/forum/viewthread.php?tid=36012&fpage=1&highlight=
[ Last edited by fastslz on 2007-12-9 at 11:24 PM ]
Recent Ratings for This Post
( 6 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| s11ss | +4 | 2007-12-05 16:36 |
| honghunter | +3 | 2008-01-14 21:38 |
| wert123 | +4 | 2008-03-12 14:01 |
| kioskboy | +2 | 2008-04-12 18:31 |
| bgfcgh | +1 | 2008-11-01 15:35 |
| NeverAgain | +2 | 2010-10-27 17:05 |
Attachments

