in reply to Opening files with japanese/chinese chars in filename

The character sets of filesystems are one of the (few) blind spots in Perls support for character sets. Perl (and Unix, go figure) consider a filename to be a null-terminated sequence of bytes without further encoding and Perl normally uses the byte-oriented APIs. Windows likely treats the file as UTF-16 or as some other charset, so there will be an API mismatch when you input the filename to your Perl script and it then turns over that name to the byte-oriented APIs.

You can try to transcode the filename using Encode or you can resort to using the 8.3 filenames (if they are enabled for the filesystem/partition in question). You can also try to use the "wide" API (OpenFileW instead of the Perl default OpenFileA) which accepts UTF-16 strings (I believe). The drawback of the wide APIs is, that the rest of Perl, like filehandles, does not know what to do with the results you get back from them.

The most likely successful approach is to use pattern matching and readdir to find the files that interest you(r program). Hopefully the byte-oriented results of readdir() will still work when passed to open().

Update: cdarke points out that OpenFile* are for 16-bit compatibility only. CreateFile* are the way to do it under the newer versions. tye's and demerphq's Win32API::File provide the functions to use those calls and the functions even return Perl filehandles!

  • Comment on Re: Opening files with japanese/chinese chars in filename