Command Line gb2312, UTF-8, Unicode, big5 Conversion Tool for vbs

Source: Internet
Author: User
Tags readfile

Gb2312, UTF-8, Unicode, big5 Conversion Tool written by vbs,
Download Conversion Tool: gb2ue. vbs (3.34 KB)

Demo
Echo "ABCDE &! @ # $ ^ <> () % ABCDE test! ">" Processing prefix .txt"
Gb2ue. vbs "processing before .txt" "processing after .txt"
Ue2u8. vbs "processed .txt"
U82gb. vbs "processed .txt"
Gb2u8. vbs "processed .txt"
U82ue. vbs "processed .txt"
Ue2gb. vbs "processed .txt"
@ ECHO: After 6 times of processing, "processed .txt" and "processed .txt" are still the same encoding.
Use

The details are as follows:Code:
'* ===================================================== ========================================================== *
'* Cmd command line encoding conversion tools include gb2312, UTF-8, Unicode, big5... support drag and drop, files are saved *
'* Codechange. vbs by: yongfa365
'* Gb2ue. vbs by: fastslz
'* ===================================================== ========================================================== *
Acode = "gb2312"
Bcode = "Unicode"
Show = "this script only supports conversion from" & acode & "to" & bcode & ". Drag a single file to this file! "
Usage1 = "Syntax 1: gb2ue. vbs [Drive] [Directory] [file name] (replace original file mode directly )"
Usage2 = "syntax 2: gb2ue. vbs [Drive] [Directory] [file name] [target drive] [Directory] [new name]/y"
Usage3 = "if the new target file already exists, use the/y parameter and replace it without prompting whether to rewrite it! "
Usage4 = "command line encoding and conversion tool by: fastslz"

Set objargs = wscript. Arguments
Set FSO = Createobject ("scripting. FileSystemObject ")
If objargs. Count = 0 then
Msgbox show & 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. Use ansi2unicode. vbs", vbinformation ," Program Unexpected termination"
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 + "" => the target file "" + GetFile + "& vbcrlf &" the target file already exists, rewrite existing files? "+ Objargs (1) +" ", vbquestion + vbyesno," rewrite ")
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 be processed" "& sourcefile &" "& vbcrlf &" the original file encoding is not "& acode &", this script only supports conversion from "& acode &" to "& bcode! ", Vbinformation," termination error"
Wscript. Quit
End if
SLZ. Close
Set SLZ = nothing
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.