in reply to Re: Saving file name with Chinese characters
in thread Saving file name with Chinese characters

Can you please show an example of using CreateFileW? I looked at the docs, but I am not too sure. Thanks.
  • Comment on Re^2: Saving file name with Chinese characters

Replies are listed 'Best First'.
Re^3: Saving file name with Chinese characters
by ikegami (Patriarch) on Apr 13, 2009 at 19:03 UTC
    Look under CreateFile (note the case) for a detailed description of each arg.

    That leaves getting a Perl handle from the Win32API::File object:

    use strict; use warnings; use Encode qw( encode ); use Symbol qw( gensym ); use Win32API::File qw( CreateFileW OsFHandleOpen CREATE_ALWAYS GENERIC_WRITE ); my $qfn = chr(0x2660); # Whatever my $win32f = CreateFileW( encode('UCS-2le', $qfn), GENERIC_WRITE, # For writing 0, # Not shared [], # Security attributes CREATE_ALWAYS, # Create and replace 0, # Special flags [], # Permission template ) or die("CreateFile: $^E\n"); OsFHandleOpen( my $fh = gensym(), $win32f, 'w' ) or die("OsFHandleOpen: $^E\n"); print $fh "Foo!\n";
      ikegami,

      Back to the original question: Your solution shows how to save a file when you *know* the encoding for one character.

      I don't know what users will upload. So I need to convert the file names on the fly. In fact, they might not even use Chinese. They might use Korean, Japanese or just English. I need a solution that would be language independent.

      Years ago, I remember seeing some Perl program that would use the bytes pragma to do the conversion. Would that help?

      Thanks ikegami.

        This new problem really has nothing to do with your original question, and should get a new thread rather than being directed at me.

        Try clearing up the problem definition while you're at it. I think you want to determine the encoding of the names of files uploaded via HTTP POST requests, but that involved guess work.