Batchography: Batch files and Unicode

Recently, I had to update my popular utility that resets NTFS files permission to support Unicode paths. I had to investigate how to add Unicode support in Batch scripts. It seems that this was a topic I forgot to add into my comprehensive Batch files programming book.

This article is the result of my investigation, in which I am going to show you how to add Unicode support to your Batch file scripts in 3 easy steps.

Step 1

Fire up your favorite text editor and then typing your script, including any Unicode characters you wish to include in the script.

Add the following command to the top of your script:

CHCP 65001 > NUL

With CHCP we are changing the current code page to UTF-8 (numerical value of 65001).

Step 3

The final step is to save the file with UTF-8 encoding but without the UTF-8 BOM markers. Unfortunately, if you use Notepad, it will save the BOM markers automatically and that will cause a problem:

As you can see from the output above, the “@echo off” failed because of the BOM bytes. You won’t be able to see the BOM bytes unless you use a special text editor or a hex-editor:

Notice the fist 3 bytes (EF BB BF).

To avoid this, I use EditPlus because it allows me to save the script with UTF-8 encoding but without the BOM markers.

Let’s test the script

That’s it!
flower separator

batchography-good-res

For more advanced Batch scripting topics, please grab a copy of the book from Amazon:

  • PaperbackĀ editionbtn-buy-on-amazon
  • E-book editionbtn-buy-on-amazon

flower separator

You might also like:

Leave a Reply