1

I want to process some files through a batch file via drag & drop under Windows.

Some of the files have unicode characters in their names, e.g. Example_ěø.txt

Unfortunately, many of the non-ASCII characters get mangled along the way. For example, with a simple batch file like

echo %*

when I drag & drop a file with the example name given above I get:

C:\>echo "C:\Example_eo.txt"
"C:\Example_eo.txt"

and so the ěø has been converted to eo, and naturally the file cannot be found.

Is there any way in a Windows batch file to access the actual unicode name/path of the files dragged & dropped onto the batch file?


ANSWER: Use chcp 65001, but to prevent the command terminating the bat file, it's necessary to route any output from the command to nul. I also found it necessary to put the following commands on the same line using &&. So my sample bat file now reads

chcp 65001 > nul && echo %* && pause

Which shows the unicode/utf-8 versions of the filenames/paths of files dropped on it.

dreftymac
  • 31,404
  • 26
  • 119
  • 182

1 Answers1

1

You can do it by using

chcp 65001

and changing the font in cmd to Lucida Console.

Bali C
  • 30,582
  • 35
  • 123
  • 152
  • 1
    Batch files don't work in code page 65001, due to bugs in the CRT's handling of this second-class-citizen code page. :-( See eg http://stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called – bobince Feb 04 '13 at 22:40
  • @bobince Oh right, it worked for me though. I will have a look at the link, thanks! – Bali C Feb 05 '13 at 08:35
  • I did try that, having found it in other similar-but-not-quite questions, but on Windows XP it seemed to prevent the bat file running at all. And now having followed your link, I see that this is a known problem with a possible solution. I'll investigate further. –  Feb 05 '13 at 13:51
  • I found that the combination of chcp 65001 and keeping all commands on a single line worked for my purposes. –  Feb 05 '13 at 15:03