Windows batch: Unicode parameters for (robo) copy command

♀尐吖头ヾ 提交于 2019-12-01 16:01:22

If

  • I add CHCP 65001 as the first line of your batch file,
  • save the file as UTF-8 without BOM, and
  • set my console font to something else than "Raster Fonts" (on my Win7 box I can choose Consolas or Lucida Console),

it works. Simple, no? :-)

(The font change is actually not necessary, provided you're not writing non-ASCII output to the console.)

I'm not certain, but I think the short (8.3) filename will be ASCII, so you could refer to it that way? You can find out the short filename with dir /X .

Resistor

I want to create a batch file (e.g. RunThis.bat) which creates directories of names that can be Russians or others.

Example:
When DOS Windows is open with prompt:

D:\>md "Russia - Шпионка"

This work in command like and the name appear correctly.

But if I try that using Notepad and save in ANSII, I can’t.
So if I use again Notepad and save in UTF-8, it will work but with garbage characters.

RunThis.bat (Notepad save UTF-8), give garbage characters.

chcp 65001
set fn14="Russia - Шпионка"
md %fn14%

The problem with notepad it uses UTF-8 with BOM.

To save the .bat using UTF-8 without BOM we must use editor like Notepad++.

RunThis.bat (Notepad++ save UTF-8 – no BOM)

chcp 65001
set fn14="Russia - Шпионка"
md %fn14%

This time its work perfectly when we run “RunThis.bat” directly from explorer.exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!