test.bat- @echo off
- set SrcFolder=C:\test\BatHome
- set DstFolder=C:\test\Batcher
- set ResultFile="%DstFolder%\Merge.txt"
- for %%a in ("%SrcFolder%\*.txt") do (
- UTF82ANSI.vbs "%%a" "%DstFolder%\%%~nxa"
- )
- (for %%a in ("%DstFolder%\*.txt") do (
- type "%%a"
- echo.
- ))>"%ResultFile%"
- start "" "%ResultFile%"
复制代码 UTF82ANSI.vbs- 'UTF82ANSI
- aCode = "UTF-8"
- bCode = "GB2312"
- Set objArgs = WScript.Arguments
-
- FileUrlSrc = objArgs(0)
- FileUrlDst = objArgs(1)
- Call WriteToFile(FileUrlDst, ReadFile(FileUrlSrc, aCode), bCode)
-
- Function ReadFile(FileUrlSrc, CharSet)
- Dim Str
- Set stm = CreateObject("Adodb.Stream")
- stm.Type = 2
- stm.mode = 3
- stm.charset = CharSet
- stm.Open
- stm.loadfromfile FileUrlSrc
- Str = stm.readtext
- stm.Close
- Set stm = Nothing
- ReadFile = Str
- End Function
-
- Function WriteToFile (FileUrlDst, Str, CharSet)
- Set stm = CreateObject("Adodb.Stream")
- stm.Type = 2
- stm.mode = 3
- stm.charset = CharSet
- stm.Open
- stm.WriteText Str
- stm.SaveToFile FileUrlDst, 2
- stm.flush
- stm.Close
- Set stm = Nothing
- End Function
复制代码 参考:VBS版文本文件编码转换工具(GB2312、UTF-8、Unicode、BIG5)
http://bbs.bathome.net/thread-3900-1-1.html |