China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-10-01 17:28
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to convert the UTF-8 encoding of a txt text file to Unicode encoding! View 7,271 Replies 17
Floor 16 Posted 2008-05-18 23:09 ·  中国 北京 联通数据上网公共出口
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
There are in the forum... Search by yourself.
Floor 17 Posted 2008-06-02 15:26 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★
Credits 109
Posts 30
Joined 2007-09-05 14:27
19-year member
UID 96621
Gender Male
Status Offline
Usage method:
Double-click or drag the file in

If using other methods besides these two, errors may occur

@echo off
if "%~1" == "" goto main


set "wfiles=%cmdcmdline:"=%"
call set "wfiles=%%wfiles:*%~d0=%%"
call set "wfiles=%%wfiles:*%~d1=%%"
call set "wfiles=%%wfiles: %~d1=" "%~d1%%"
set wfiles="%~d1%wfiles%"

if "%cmdcmdline:~0,3%" == "cmd" call :ddd %wfiles%
if not "%cmdcmdline:~0,3%" == "cmd" set wfiles=%*
goto main

:ddd
cd/d "%~dp1"
goto :eof

::--------------------------------------------------------------
:main



echo 1 GB2312
echo 2 Big5
echo 3 Shift_JIS
echo 4 EUC-KR
echo 5 UTF-8
echo 6 Unicode
echo.
echo A --> B
echo A=? (1-6)
set /p aaa=
echo B=? (1-6)
set /p bbb=

echo %aaa%|findstr /be "" >nul ||goto :eof
echo %bbb%|findstr /be "" >nul ||goto :eof
if "%aaa%" == "%bbb%" goto :eof

if not defined wfiles set /p wfiles=Files???
if not defined wfiles goto :eof


echo Set objFSO = CreateObject("Scripting.FileSystemObject") > MakeBOM.vbs
echo Set objFile = objFSO.CreateTextFile("Unicode.BOM",,true) >> MakeBOM.vbs
cscript //Nologo MakeBOM.vbs

md After_Convert\tmp



:loop
set vvv=%aaa%
if "%aaa%" == "6" set vvv=%bbb%

for /f "tokens=%vvv%" %%a in ("936 950 932 949 65001") do (
reg add "HKCU\Console\%%SystemRoot%%_System32_cmd.exe" /v CodePage /t REG_DWORD /d %%a /f >nul
)

if not "%aaa%" == "6" (
if not "%bbb%" == "6" (
start /wait /min cmd /u /c "for %%a in (%%wfiles%%) do copy Unicode.BOM tmpfile.tmp&type "%%~fa" >> tmpfile.tmp&move /y tmpfile.tmp After_Convert\tmp\"%%~nxa""
set aaa=6
set wfiles=After_Convert\tmp\*
goto loop
)
)


if "%bbb%" == "6" (
start /wait /min cmd /u /c "for %%a in (%%wfiles%%) do copy Unicode.BOM tmpfile.tmp&type "%%~fa" >> tmpfile.tmp&move /y tmpfile.tmp After_Convert\"%%~nxa""
) else (
start /wait /min cmd /c "for %%a in (%%wfiles%%) do type "%%~fa" > After_Convert\"%%~nxa"")



reg delete "HKCU\Console\%%SystemRoot%%_System32_cmd.exe" /v CodePage /f >nul
del MakeBOM.vbs
del Unicode.BOM
rd After_Convert\tmp /s /q
start After_Convert


[ Last edited by mkd on 2008-6-2 at 10:35 PM ]
Floor 18 Posted 2009-12-02 17:51 ·  中国 北京 联通
初级用户
★
Credits 39
Posts 27
Joined 2007-09-10 17:46
19-year member
UID 97038
Gender Male
Status Offline
Oh, expert, I'm really astonished. There's just too much to learn.
Forum Jump: