Search code examples
windowsbatch-fileunicodedrag-and-dropunicode-string

Drag & Drop of files with unicode names to batch file in Windows


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.


Solution

  • You can do it by using

    chcp 65001
    

    and changing the font in cmd to Lucida Console.