Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I work with Japanese characters in filenames on the Windows command line and in batch scripts?

I am working on a Japanese version of Windows 7, in a Japanese environment and unfortunately many of the file and folder names I need to work with use Japanese characters.

For example, I have this line in a .bat file:

xcopy * "C:\blahblah\動作確認\" /E /R /K /Y /I 

However, inside the C:\blahblah\ folder, this is the name of the folder I get: C:\blahblah\蜍穂ス懃「コ隱構

The problem is that 動作確認 has been transformed into 蜍穂ス懃「コ隱構. The latter, while it uses Asian characters (and punctuation) is meaningless gibberish, and not even all of them Japanese characters.

I researched this problem and I found that many people using English localizations of Windows have an issue where they see question marks instead of Japanese characters. That's not what happens for me using my Japanese localization of Windows - if I launch cmd and navigate to the parent of the source folder from which I want to copy, run dir and get this output:

2014/02/07  16:36    <DIR>          蜍穂ス懃「コ隱構

This is the gibberish, not the actual Japanese.

So what do I have to do to make my xcopy command inside my batch file work?

like image 798
PokeJoe Avatar asked Dec 21 '25 12:12

PokeJoe


1 Answers

I guess that you have already found a work around but let me answer.

If you have a UTF-8 byte sequence of a string 動作確認 and parse it as a CP932(a.k.a. Shift-JIS) byte sequence, you will get 蜍穂ス懃「コ隱構 or a similar string.

Japanese versions of Windows have used CP932 as a default encoding so we have to specify file/dir names in CP932.

In your case, you must have written your .bat file in UTF-8. You should write it in CP932.

like image 55
t_motooka Avatar answered Dec 24 '25 08:12

t_motooka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!