Windows批处理:为(ROBO)的复制命令统一code参数 [英] Windows batch: Unicode parameters for (robo) copy command
问题描述
我需要多个文件在一个批处理文件复制。该文件具有映射到不同的codepages统一code名称。
示例:
设置ArabicFile =ڊڌڵڲڛشس
设置CyrillicFile =щЖЛдЉи
设置GermanFile =布赫尔复制%ArabicFile%SomePlaceElse
复制%CyrillicFile%SomePlaceElse
复制%GermanFile%SomePlaceElse
问题:批处理文件不能是单向code
问:如何写的Uni code文件名的批处理文件,以便复制命令识别它们。
注:
我不关心文件名的显示方式。结果
其实批处理文件确实远不止复制这些文件,我只是简化为使问题更清晰的描述。
正确的批处理文件:
使用Arnout的回答我修改我的批处理文件如下。它现在可以正常工作,而不需要一个字体改变(这将是混乱的,因为Arnout评论)
关闭@echoCHCP 65001设置ArabicFolder =ڊڌڵڲڛشس
设置CyrillicFolder =щЖЛдЉи
设置GermanFolder =布赫尔的Robocopy / E D:\\ TEMP \\测试\\%ArabicFolder%D:\\ TEMP \\ TEST2 \\%ArabicFolder%/log:copy.log
的Robocopy / E D:\\ TEMP \\测试\\%CyrillicFolder%D:\\ TEMP \\ TEST2 \\%CyrillicFolder%/log+:copy.log
的Robocopy / E D:\\ TEMP \\测试\\%GermanFolder%D:\\ TEMP \\ TEST2 \\%GermanFolder%/log+:copy.log
如果
- 我想补充
CHCP 65001
为您的批处理文件的第一行, - 将文件保存为UTF-8无BOM和
- 我的控制台字体设置为光栅字体别的东西(在我的Win7箱子,我可以选择索拉或龙力控制台)
它的工作原理。很简单,不是吗? : - )
(字体的变化其实是没有必要的,只要你不写非ASCII输出到控制台上。)
I need to copy multiple files in a single batch file. The files have Unicode names that map to different codepages.
Example:
set ArabicFile=ڊڌڵڲڛشس
set CyrillicFile=щЖЛдЉи
set GermanFile=Bücher
copy %ArabicFile% SomePlaceElse
copy %CyrillicFile% SomePlaceElse
copy %GermanFile% SomePlaceElse
Problem: Batch files cannot be Unicode.
Question: How can I write the Unicode file names to the batch file so that the copy command recognizes them?
Notes:
I do not care how the file names are displayed.
Actually the batch file does much more than just copy these files, I just simplified the description to make the problem clearer.
Correct batch file:
With Arnout's answer I modified my batch file as follows. It now works correctly without requiring a font change (which would be messy, as Arnout commented).
@echo off
chcp 65001
set ArabicFolder=ڊڌڵڲڛشس
set CyrillicFolder=щЖЛдЉи
set GermanFolder=Bücher
robocopy /e d:\temp\test\%ArabicFolder% d:\temp\test2\%ArabicFolder% /log:copy.log
robocopy /e d:\temp\test\%CyrillicFolder% d:\temp\test2\%CyrillicFolder% /log+:copy.log
robocopy /e d:\temp\test\%GermanFolder% d:\temp\test2\%GermanFolder% /log+:copy.log
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.)
这篇关于Windows批处理:为(ROBO)的复制命令统一code参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!