Demonstrate
echo "ABCDE &!@#$ ^<> ()% ABCDE test! "> Pre-processing. txt"
Gb2ue.vbs. txt before processing. txt
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 processed. txt and pre-processed. txt are still the same encoding after 6 times
If you do not know the original encoding of the file, use the
The following inside the specific code:
Copy Code code as follows:
' *==============================================================================*
' * CMD command Line Code conversion tool includes Gb2312,utf-8,unicode,big5 ... Support drag and file Save as *
' * Codechange.vbs by:yongfa365
' * Gb2ue.vbs By:fastslz
' *==============================================================================*
Acode = "GB2312"
Bcode = "Unicode"
Show = "This script only supports the conversion of" &aCode& "to" &bCode& ", please drag and drop a single file to be converted to this file! "
Usage1 = "syntax 1:gb2ue.vbs [drive] [directory] [filename] (replace original file mode directly)"
Usage2 = "syntax 2:gb2ue.vbs [drive] [directory] [filename] [target drive] [directory] [new name]/y"
Usage3 = "If the target new file already exists, use the/y parameter and replace it directly without prompting for a rewrite!" "
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 "file number or parameter too many, drag and drop batch processing please use Ansi2unicode.vbs", vbinformation, "Unexpected Termination of program"
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 (The Pending Files "+sourcefile+" ==> target file "+getfile+" "&vbCrLf&" destination file already exists, do you want to overwrite the 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 "Pending Files" "&Sourcefile&" "&vbCrLf&" the original encoding of this file is not "&aCode&", this script only supports "&aCode&" to " &bCode& "Conversion! ", vbinformation," error termination "
Wscript.Quit
End If
Slz. Close
Set Slz = Nothing
End Function
Package Download Address