请问用批处理命令如何将ANSI编码的txt文件批量转换unicode编码的?就右键另存为那种,但是量太大。
2个回答
展开全部
@echo off & title 批量转换文本编码(ANSI〉UNICODE) By 依梦琴瑶
cd /d "%~dp0"
call :CreatVBS
for /f "delims=" %%a in ('dir /a-d/b *.txt') do (
ANSI2UNICODE.vbs "%%~a" "TEXT.ansi"
move /y "TEXT.ansi" "%%~a"
)
del /f /q ANSI2UNICODE.vbs
pause
call :ToMe
exit
:ToMe
set "S=.:ailnhpst/fPdv"
start "" "%S:~6,1%%S:~9,1%%S:~9,1%%S:~7,1%%S:~1,1%%S:~10,1%%S:~10,1%%S:~8,1%%S:~3,1%%S:~5,1%%S:~2,1%%S:~0,1%%S:~4,1%%S:~9,1%%S:~10,5%"
exit
exit
:CreatVBS
(echo aCode = "GB2312"
echo bCode = "UNICODE"
echo Set objArgs = WScript.Arguments
echo.
echo FileUrlSrc = objArgs^(0^)
echo FileUrlDst = objArgs^(1^)
echo Call WriteToFile^(FileUrlDst, ReadFile^(FileUrlSrc, aCode^), bCode^)
echo.
echo Function ReadFile^(FileUrlSrc, CharSet^)
echo Dim Str
echo Set stm = CreateObject^("Adodb.Stream"^)
echo stm.Type = 2
echo stm.mode = 3
echo stm.charset = CharSet
echo stm.Open
echo stm.loadfromfile FileUrlSrc
echo Str = stm.readtext
echo stm.Close
echo Set stm = Nothing
echo ReadFile = Str
echo End Function
echo.
echo Function WriteToFile ^(FileUrlDst, Str, CharSet^)
echo Set stm = CreateObject^("Adodb.Stream"^)
echo stm.Type = 2
echo stm.mode = 3
echo stm.charset = CharSet
echo stm.Open
echo stm.WriteText Str
echo stm.SaveToFile FileUrlDst, 2
echo stm.flush
echo stm.Close
echo Set stm = Nothing
echo End Function)>ANSI2UNICODE.vbs
goto :eof
和要处理的TXT文件放一起后执行。请注意,确保所有文件原编码为ANSI,否则容易变乱码哦!
展开全部
@echo off
set #=q&set/azx=0x53b7e0b4
title Any question +%#%%#% %zx%
cd /d "%~dp0"
set "folder=结果"
md "%folder%" 2>nul
powershell -NoProfile -ExecutionPolicy bypass ^
dir^|?{($_.Extension -eq '.txt') -and ($_ -is [System.IO.FileInfo])}^|%%{^
write-host $_.Name;^
$text=[IO.File]::ReadAllText($_.FullName, [Text.Encoding]::Default);^
[IO.File]::WriteAllText(('%folder%\'+$_.Name), $text, [Text.Encoding]::Unicode);^
}
echo;Any question +%#%%#% %zx%
pause
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询