Saturday, January 6, 2018

List file name not in English characters

This blog doesn't really relate to Salesforce, but I come across this issue when need to prepare files name for Salesforce data loader.

This blog only applicable when using Windows machine. If all the files name is in English, there is no issue that you can just use "dir" from the command prompt. But, my issue when the files name is in Korean and Japanese. Manually to copy and paste file name one by one consume too many times if there is a lot of files.

Once I thought that need to install kind of free app for directory printer, but can we just use out of the box thing available from windows? After doing some research, I'm able to achieve this without any extra tool, so I think just to blog it and share with the public.

There is a command called chcp at Windows command prompt. Chcp command displays the number of the active console code page, or changes the console's active console code page. Used without parameters, chcp displays the number of the active console code page.

Depends on your windows language and region setting the result may be different, here is mine, 437 mean United States.

If you type "dir" from the folder with Japanese or Korean or Chinese, they will show as ? for each character.

Because Japanese, Korean, or Chinese support by UTF-8, we can change the console to 65001, by type chcp 65001.

But, if you type "dir" after chcp 65001, you will still see the same ? as earlier in the screen. But, if you copy and paste to Notepad, they will be in their original characters.

Another way is to store the result into a text file dir /b >result.txt 
/b mean only to get the file name without any other data.
>result.txt mean all dir result will store in a new file name called result.txt (you can change to any name preferred.


No comments:

Post a Comment

Page-level ad