Jos*_*efZ 5

    \n
  1. 保存批处理文件时UTF-8 不带 字节顺序标记
  2. \n
  3. 在代码页中65001运行该批处理文件(即UTF-8在 Windowscmd环境中)。
  4. \n
\n\n

示例批处理文件

\n\n
@ECHO OFF\nSETLOCAL EnableExtensions\ndir /B "D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))"\necho HiWorld>"D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))\\\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94).txt"\ndir /B "D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))"\ntype "D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))\\\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94).txt"\n
Run Code Online (Sandbox Code Playgroud)\n\n

输出(您可以看到默认代码页可能是852;您的代码页可能不同):

\n\n
==> chcp\nActive code page: 852\n\n==> D:\\bat\\SO\\46129875.bat\nFile Not Found\nThe system cannot find the path specified.\nFile Not Found\nThe system cannot find the path specified.\n\n==> chcp 65001\nActive code page: 65001\n\n==> D:\\bat\\SO\\46129875.bat\n\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94).txt\nHiWorld\n\n==>\n
Run Code Online (Sandbox Code Playgroud)\n\n

编辑:根据有价值的Eryksun 评论更新脚本

\n\n
@:: How to create a file with Chinese characters in the name by Windows batch file? \n@:: this file must be saved in `UTF-8` encoding, preferably without Byte Order Mark\n@ECHO OFF\nSETLOCAL EnableExtensions\n:: save the active code page number parsing "Active code page: NNN" output from CHCP\nfor /F "tokens=4" %%G in (\'chcp\') do set "_chcp=%%G"\n:: change the active console code page to UTF-8 \n>NUL chcp 65001\n:: DEBUGGING: erase all .TXT files from target folder \n>NUL 2>&1 del "D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))\\*.txt"\n:: create a file with Chinese characters in the name inside target folder \necho HiWorld>"D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))\\\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94).txt"\necho Hi All>>"D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))\\\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94).txt"\n:: DEBUGGING: show the name of created file\ndir /B "D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))"\n:: DEBUGGING: show the content of created file\ntype "D:\\bat\\UnASCII Names\\CJK (\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94))\\\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94).txt"\n:: change the active console code page back to previously saved value \n>NUL chcp %_chcp%\n
Run Code Online (Sandbox Code Playgroud)\n\n

输出

\n\n
==> chcp\nActive code page: 852\n\n==> D:\\bat\\SO\\46129875.bat\n\xe4\xb8\xad\xe6\x96\x87(\xe7\xb9\x81\xe9\xab\x94).txt\nHiWorld\nHi All\n\n==> chcp\nActive code page: 852\n\n==>\n
Run Code Online (Sandbox Code Playgroud)\n