cya*_*cya 1 unicode character batch-file
问题是:
echo HiWorld > c:\filename.txt
Run Code Online (Sandbox Code Playgroud)
filename是中国人。
怎么做?
UTF-8 不带 字节顺序标记。65001运行该批处理文件(即UTF-8在 Windowscmd环境中)。示例批处理文件:
\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"\nRun Code Online (Sandbox Code Playgroud)\n\n输出(您可以看到默认代码页可能是852;您的代码页可能不同):
==> 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==>\nRun 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%\nRun 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==>\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
4059 次 |
| 最近记录: |