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:
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!
For more advanced Batch scripting topics, please grab a copy of the book from Amazon:
You might also like:
- Batchography: Converting numbers to characters (or the CHR() function)
- How to show saved Windows 8 and Windows 10 Wifi passwords
- How to show saved Windows 7 Wifi passwords
- Free WifiShare Tool: Turning your laptop into a hotspot and internet connection sharing station
- Free software
- How to get unlimited free Internet at Airports
- Batchography: The Art of Batch Files Programming – book
- Backup and restore NTFS files permission with the ResetPermission utility