|
moonofwell
新手上路

积分 16
发帖 6
注册 2007-11-30
状态 离线
|
『楼 主』:
[求助]如何将txt文本文件的utf-8编码转换成unicode编码!!
使用 LLM 解释/回答一下
如何将txt文本文件的utf-8编码转换成unicode编码!!
注:很多个文件,不能一个一个处理,得批量处理!!!
我想转换编码的目的是要用Excel直接打开txt文件,但是打开utf-8编码的文本会变成乱码,必须得转换成unicode编码的文本文件才行。可以用记事本打开文本文件,然后“另存为”时选择编码,但是文件太多,不能一个一个操作。看看哪个高手能解决这个问题!!!
How to convert the UTF-8 encoding of a TXT text file to the Unicode encoding!!
Note: There are many files, and they can't be processed one by one. I want to convert the encoding because I need to open the TXT file directly with Excel, but opening a UTF-8 encoded text will become garbled, and it must be converted to a Unicode encoded text file. I can use Notepad to open the text file and then choose the encoding when "Save As", but there are too many files to operate one by one. See which expert can solve this problem!!!
|
|
2007-11-30 10:10 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
@echo off
for /f "delims=" %%a in ('dir /s /b /a-d D:\test\*.txt') do (
call cmd /u /c type "%%a">"%%~dpna.U"
call echo move /y "%%~dpna.U" "%%a"
)
pause
```@echo off
for /f "delims=" %%a in ('dir /s /b /a-d D:\test\*.txt') do (
call cmd /u /c type "%%a">"%%~dpna.U"
call echo move /y "%%~dpna.U" "%%a"
)
pause```
|

第一高手 第二高手
我的小站
 |
|
2007-11-30 11:17 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
好像批处理并不能直接处理utf-8编码的文本
It seems that batch processing can't directly handle text encoded in UTF-8.
|

 |
|
2007-11-30 11:32 |
|
|
moonofwell
新手上路

积分 16
发帖 6
注册 2007-11-30
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
不行啊,运行之后,产生了几个.u格式的文件,用记事本打开也都是乱码,不是我想要的结果欧!!!高手再看看!!!
It doesn't work. After running, several .u format files are generated. Opening them with Notepad is all garbled code, which is not the result I want!!! Experts, take a look again!!!
|
|
2007-11-30 11:34 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
|
2007-11-30 11:35 |
|
|
moonofwell
新手上路

积分 16
发帖 6
注册 2007-11-30
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
不行,编码要选择utf-8,我要转换的是utf-8到unicode。你用记事本随便写几句话,然后另存为,选择编码为:utf-f,保存
然后再运行你的程序,你看看吧。
Last edited by moonofwell on 2007-11-30 at 11:46 AM ]
No, the encoding should be selected as utf-8. I need to convert utf-8 to unicode. Just write a few sentences in Notepad, then save as, select the encoding as: utf-f, and save. Then run your program, and you can take a look.
Last edited by moonofwell on 2007-11-30 at 11:46 AM ]
|
|
2007-11-30 11:44 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
既然zh159批处理并不能直接处理utf-8也就没办法了,借助第三方工具吧
Since the zh159 batch processing can't directly handle UTF-8, there's no way around it. We have to rely on third-party tools.
|

第一高手 第二高手
我的小站
 |
|
2007-11-30 12:05 |
|
|
moonofwell
新手上路

积分 16
发帖 6
注册 2007-11-30
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
第三方工具我找到了,ConvertZ ver 7.40 ,如果能用dos批处理或vbs搞定就更好了!!!(*^_^*)
I found a third - party tool, ConvertZ ver 7.40. It would be even better if it could be done with DOS batch processing or VBS! (*^_^*)
|
|
2007-11-30 12:11 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
UTF82Unicode.vbs
[code]
Set objArgs = WScript.Arguments
For I = 0 To objArgs.Count - 1
FileUrl = objArgs(I)
Call WriteToFile(FileUrl, ReadFile(FileUrl, "UTF-8"), "Unicode")
Next
Function ReadFile(FileUrl, CharSet)
Dim Str
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.loadfromfile FileUrl
Str = stm.readtext
stm.Close
Set stm = Nothing
ReadFile = Str
End Function
Function WriteToFile (FileUrl, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile FileUrl, 2
stm.flush
UTF82Unicode.vbs
Set objArgs = WScript.Arguments
For I = 0 To objArgs.Count - 1
FileUrl = objArgs(I)
Call WriteToFile(FileUrl, ReadFile(FileUrl, "UTF-8"), "Unicode")
Next
Function ReadFile(FileUrl, CharSet)
Dim Str
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.loadfromfile FileUrl
Str = stm.readtext
stm.Close
Set stm = Nothing
ReadFile = Str
End Function
Function WriteToFile (FileUrl, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile FileUrl, 2
stm.flush
|
|
2007-11-30 13:21 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
UTF82Unicode.vbs
Set objArgs = WScript.Arguments
For I = 0 To objArgs.Count - 1
FileUrl = objArgs(I)
Call WriteToFile(FileUrl, ReadFile(FileUrl, "UTF-8"), "Unicode")
Next
Function ReadFile(FileUrl, CharSet)
Dim Str
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.loadfromfile FileUrl
Str = stm.readtext
stm.Close
Set stm = Nothing
ReadFile = Str
End Function
Function WriteToFile (FileUrl, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile FileUrl, 2
stm.flush
stm.Close
Set stm = Nothing
End Function
@echo off
for /f "delims=" %%a in ('dir /s /b /a-d D:\test\*.txt') do UTF82Unicode.vbs "%%a"
pause
直接替换模式,请先测试后应用
UTF82Unicode.vbs
Set objArgs = WScript.Arguments
For I = 0 To objArgs.Count - 1
FileUrl = objArgs(I)
Call WriteToFile(FileUrl, ReadFile(FileUrl, "UTF-8"), "Unicode")
Next
Function ReadFile(FileUrl, CharSet)
Dim Str
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.loadfromfile FileUrl
Str = stm.readtext
stm.Close
Set stm = Nothing
ReadFile = Str
End Function
Function WriteToFile (FileUrl, Str, CharSet)
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset = CharSet
stm.Open
stm.WriteText Str
stm.SaveToFile FileUrl, 2
stm.flush
stm.Close
Set stm = Nothing
End Function
@echo off
for /f "delims=" %%a in ('dir /s /b /a-d D:\test\*.txt') do UTF82Unicode.vbs "%%a"
pause
Direct replacement mode, please test before applying
|

第一高手 第二高手
我的小站
 |
|
2007-11-30 13:22 |
|
|
moonofwell
新手上路

积分 16
发帖 6
注册 2007-11-30
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
可以了,多谢了哥们儿,真是高手阿!!!
Okay, thanks buddy, you're really a master!!!
|
|
2007-11-30 13:30 |
|
|
gameyixiu
初级用户
 
积分 47
发帖 18
注册 2007-9-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
楼主是utf-8编码转换成unicode
而我的问题是:
如何将UTF-8转成ANSI
还有unicode如何转成ANSI
用批处理文件如何实现?
请高手解答
The LZ is converting UTF-8 encoding to Unicode.
And my question is:
How to convert UTF-8 to ANSI
And how to convert Unicode to ANSI
How to implement it with a batch file?
Please experts answer
|
|
2007-12-7 17:06 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
|
2007-12-7 20:54 |
|
|
gameyixiu
初级用户
 
积分 47
发帖 18
注册 2007-9-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
谢谢楼上的
Last edited by gameyixiu on 2007-12-10 at 03:45 PM ]
Thanks to the upstairs
Last edited by gameyixiu on 2007-12-10 at 03:45 PM ]
|
|
2007-12-10 15:43 |
|
|
joson
新手上路

积分 2
发帖 1
注册 2008-5-18
状态 离线
|
|
2008-5-18 22:10 |
|