问题描述
我仍在使用.m3u播放列表文件的转换器,将它们从Windows Media Player生成的格式转换成Teamspeak 3插件Soundboard接受的格式。
I am still working on a converter for .m3u playlist files that ports them from a Windows Media Player generated format into a format that gets accepted by the Teamspeak 3 plugin "Soundboard".
主转换器现在完成,我遇到最后一个问题:
当使用批处理脚本编写新代码时,它将使用 echo a-lot保存到ANSI编码文件中-of-text-and-code>> 3.txt
,似乎插件只能打开UTF-8编码的文件。
The main converter is finished now and I encountered a last problem:When writing the new code with a Batch script it gets saved into an ANSI encoded file using echo a-lot-of-text-and-code >> 3.txt
and it seems like the plugin can only open UTF-8 encoded files.
有没有办法更改3的编码.txt从ANSI到UTF-8只有批量?
Is there any way to change the encoding of 3.txt from ANSI to UTF-8 with Batch only?
问候,Joe
推荐答案
它进行了一些实验,但我成功地调整了 Simon Sheppard的UCS-2编码方法a>以批处理将文件编码为UTF-8。
It took a bit of experimentation, but I successfully tweaked Simon Sheppard's UCS-2 encode method to encode a file as UTF-8 with batch.
@echo off
setlocal
:: utf8.bat infile outfile
:: convert infile to utf8 and save as outfile
if not exist "%~1" goto usage
if "%~2"=="" goto usage
set "infile=%~f1"
set "outfile=%~f2"
:: store current console codepage to var
for /f "tokens=2 delims=:" %%I in ('chcp') do set "_codepage=%%I"
:: temporarily change console codepage to UTF-8
>NUL chcp 65001
:: set byte order mark for outfile
>"%outfile%" set /p "=" <NUL
:: dump infile to outfile encoded as UTF-8
>>"%outfile%" type "%infile%"
:: restore console to original codepage
>NUL chcp %_codepage%
goto :EOF
:usage
echo Usage: %~nx0 infile outfile
此脚本本身需要以ANSI编码保存。
This script itself needs to be saved in ANSI encoding, though.
这篇关于通过批量保存UTF-8中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!