in reply to renaming filenames

Perl punts on Unicode for most OS related interactions because different OSs handle Unicode differently, or not at all (see When Unicode Does Not Happen).

For Windows you can call the Win32 API MoveFile function to get the job done:

use strict; use warnings; use utf8; use Win32::API; my $moveFile = Win32::API->new("Kernel32", MoveFileW => 'PP', "I"); my $to = 'poesía'; my $from = 'canción'; $moveFile->Call(Encode::encode("UTF-16LE", $from), Encode::encode("UTF-16LE", $to));
True laziness is hard work

Replies are listed 'Best First'.
Re^2: renaming filenames
by andalou (Novice) on Aug 16, 2012 at 04:09 UTC

    It doesn't work. It only works if the values of $from and $to don't
    contain any accents, as in: $from=song and $to=poem but it doesn't work
    if they contain accents.

    The editor I'm using is vim, so I'm saving my files in utf-8
    encoding.

      The sample script shown worked as expected for me using Windows 7 and Perl 5.10.1 (ActiveState MSWin32-x86-multi-thread build). In what way doesn't it work for you?

      True laziness is hard work

        If I have a file called canción, without any extension, and I want to
        rename it to poesía, without extension, it doesn't do it.
        The file canción remains the same.

        Also if you have a file, say ola.txt, and you want to convert it to
        mas.txt, it won't do it. It only works if the filename has at least 8
        characters including point and extension.
        Moreover, if the $to filename, has equal or more number of characters
        than the $from filename and this has at least 10 characters, strange
        characters appear on the $to filename.

        For example if I want to convert television to publishing I get
        publishing尀⩷␩)ꡀⅦ