本帖最后由 czjt1234 于 2024-1-17 21:11 编辑
或者再弄个utf8转ansi的批处理或vbs或ps
在你的每个批处理的开头调用一下
比如把下面的vbs保存为 d:\UTF8toANSI.vbs
然后在你的批处理开头加上
start /w WScript.exe d:\UTF8toANSI.vbs "xxx.ini"
支持命令行参数,比如 start /w WScript.exe d:\UTF8toANSI.vbs "%%i"
- Dim oStream, file, s
-
- file = wsh.Arguments(0)
- If checkUTF8(file) = False Then wsh.Quit()
- Set oStream = CreateObject("ADODB.Stream")
- oStream.Type = 2 'adTypeText
- oStream.Mode = 3 'adModeReadWrite
- oStream.Charset = "UTF-8"
- oStream.Open()
- oStream.LoadFromFile file
- s = oStream.ReadText()
- oStream.Close()
- oStream.Charset = "GB2312"
- oStream.Open()
- oStream.WriteText s
- oStream.SaveToFile file, 2 'adSaveCreateOverWrite
- oStream.Close()
-
- Function checkUTF8(ByVal file)
- Dim oStream, oRegExp, arr(), s
- Set oStream = CreateObject("ADODB.Stream")
- oStream.Type = 1 'adTypeBinary
- oStream.Mode = 3 'adModeReadWrite
- oStream.Open()
- oStream.LoadFromFile file
- If oStream.Size = 0 Then
- checkUTF8 = True
- Exit Function
- End If
- ReDim arr(oStream.Size - 1)
- For s = 0 To oStream.Size - 1
- arr(s) = ChrW(AscB(oStream.Read(1)))
- Next
- oStream.Close()
- s = "[\xC0-\xDF]([^\x80-\xBF]|$)" & _
- "|[\xE0-\xEF].{0,1}([^\x80-\xBF]|$)" & _
- "|[\xF0-\xF7].{0,2}([^\x80-\xBF]|$)" & _
- "|[\xF8-\xFB].{0,3}([^\x80-\xBF]|$)" & _
- "|[\xFC-\xFD].{0,4}([^\x80-\xBF]|$)" & _
- "|[\xFE-\xFE].{0,5}([^\x80-\xBF]|$)" & _
- "|[\x00-\x7F][\x80-\xBF]" & _
- "|[\xC0-\xDF].[\x80-\xBF]" & _
- "|[\xE0-\xEF]..[\x80-\xBF]" & _
- "|[\xF0-\xF7]...[\x80-\xBF]" & _
- "|[\xF8-\xFB]....[\x80-\xBF]" & _
- "|[\xFC-\xFD].....[\x80-\xBF]" & _
- "|[\xFE-\xFE]......[\x80-\xBF]" & _
- "|^[\x80-\xBF]"
- Set oRegExp = New RegExp
- oRegExp.MultiLine = False
- oRegExp.Pattern = s
- checkUTF8 = Not oRegExp.Test(Join(arr, ""))
- End Function
复制代码
|