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
CHCP 65001
as the first line of your batch file,it works. Simple, no? :-)
(The font change is actually not necessary, provided you're not writing non-ASCII output to the console.)
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:
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.
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)
This time its work perfectly when we run “
RunThis.bat
” directly fromexplorer.exe
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
.