in reply to Re^2: renaming filenames
in thread renaming filenames

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

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

    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尀⩷␩)ꡀⅦ

        I've already posted my code at the beginning of this thread:

        #!perl use utf8; my $directory = '.'; opendir (MYHANDLE , $directory) || die "Cant open directory :$!\n"; my @files = readdir MYHANDLE; closedir MYHANDLE; foreach (@files) { my $original = $_; s/canción/poesía/; rename "$directory\\$original", "$directory\\$_"; }

        And GrandFather proposed this code:

        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));

        which doesn't work for the reasons explained in my previous message.