![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-12 21:27 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] How to convert the UTF-8 encoding of a txt text file to Unicode encoding! |
| Printable Version 6,910 / 17 |
| Floor1 moonofwell | Posted 2007-11-30 10:10 |
| 新手上路 Posts 6 Credits 16 | |
|
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!!! |
|
| Floor2 fastslz | Posted 2007-11-30 11:17 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
```@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``` |
|
| Floor3 zh159 | Posted 2007-11-30 11:32 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
It seems that batch processing can't directly handle text encoded in UTF-8.
|
|
| Floor4 moonofwell | Posted 2007-11-30 11:34 |
| 新手上路 Posts 6 Credits 16 | |
|
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!!!
|
|
| Floor5 fastslz | Posted 2007-11-30 11:35 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
Oh, really? I tested with ANSI.
|
|
| Floor6 moonofwell | Posted 2007-11-30 11:44 |
| 新手上路 Posts 6 Credits 16 | |
|
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 ] |
|
| Floor7 fastslz | Posted 2007-11-30 12:05 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
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.
|
|
| Floor8 moonofwell | Posted 2007-11-30 12:11 |
| 新手上路 Posts 6 Credits 16 | |
|
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! (*^_^*)
|
|
| Floor9 fastslz | Posted 2007-11-30 13:21 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
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 |
|
| Floor10 fastslz | Posted 2007-11-30 13:22 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
UTF82Unicode.vbs
Direct replacement mode, please test before applying |
|
| Floor11 moonofwell | Posted 2007-11-30 13:30 |
| 新手上路 Posts 6 Credits 16 | |
|
Okay, thanks buddy, you're really a master!!!
|
|
| Floor12 gameyixiu | Posted 2007-12-07 17:06 |
| 初级用户 Posts 18 Credits 47 | |
|
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 |
|
| Floor13 fastslz | Posted 2007-12-07 20:54 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
Command Line GB2312, UTF - 8, Unicode, BIG5... Encoding Conversion Tool VBS Version
http://www.cn-dos.net/forum/viewthread.php?tid=35986&fpage=1&highlight= Text File Encoding Query Tool QueryCode.vbs http://www.cn-dos.net/forum/viewthread.php?tid=36012&fpage=1&highlight= |
|
| Floor14 gameyixiu | Posted 2007-12-10 15:43 |
| 初级用户 Posts 18 Credits 47 | |
|
Thanks to the upstairs
[ Last edited by gameyixiu on 2007-12-10 at 03:45 PM ] |
|
| Floor15 joson | Posted 2008-05-18 22:10 |
| 新手上路 Posts 1 Credits 2 | |
|
Not bad, learning!
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |