Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is in reference to Re: Unicode in filenames.

#!perl use utf8; use strict; use diagnostics; use Win32API::File 0.08 qw(:ALL); print "$Win32API::File::VERSION\n"; # 0.10 #createFile('abc.txt'); # system cannot find specified file #createFile('C:/abc.txt'); # system cannot find specified file #createFile('//?/C:/abc.txt'); # network path was not found CreateFileW('中文.txt', GENERIC_WRITE, FILE_SHARE_READ, +[], CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); print "last err: $^E\n";

Using the three outcommented calls gives me the errors noted in the comments. They are retranslated into English, so they are not 100% properly named.

Using the last call (what is looks like unmolested by PM: CreateFileW('中文.txt', ...) actually creates a file (empty error message), only I expect the filename 中文, but actually get the name 룤螖琮瑸Ā峘ŝ. As before, this is on NTFS in Windows 2000.

Help me, Obi-tye Kenobi! You are my only hope.

Replies are listed 'Best First'.
Re: Unicode in filenames (part 2)
by Thelonius (Priest) on Mar 21, 2006 at 01:39 UTC
    my $filename = "\x{4e2d}\x{63f7}"; # or any other way of creating utf8 string my $ret = CreateFileW(encode("utf16le", $filename . "\0"), GENERIC_WRITE, FILE_SHARE_READ, [], CREATE_ALWAYS, FILE_ATTRIBUTE_NO +RMAL, 0);

      Thank you, Thelonius! That works great.

      Obviously, the module documentation needs fixing. How do I go about that?

      Any idea why the three createFile calls are failing?

        I would send any change requests to the module author, tyemq@cpan.org and the libwin32 maintainer, jand@activestate.com.

        Change requests are more likely to be made expeditiously if you submit them as patches (another Larry Wall claim to fame).

        Calling createFile with just the file name defaults to "r ke" access, i.e. GENERIC_READ, OPEN_EXISTING.

        Did the files exist?

        createFile() probably wraps CreateFileA() which is the single byte version.
Re: Unicode in filenames (part 2)
by diotalevi (Canon) on Mar 21, 2006 at 01:41 UTC

    If you don't get a response here, try the ActiveState email list and perhaps perl5-porters if the previous doesn't pan out.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊