Thanks for reply. Um.. to narrow down the err possibility, I've cut and paste the 2 cols into a text file, use notepad, and save as UTF-8. But please tell me if that still not the version that Perl happy with.
Here's my code and there are 2 paths see the remarked lines as version 2 :
use Win32API::File 0.08 qw( :ALL );
#use Win32::Unicode::File;
binmode STDOUT, ":utf8";
open F, "Result_fineName.txt";
#binmode F, ":utf8"; # binmode or not still won't work
my @list = <F>;
close F; chomp @list;
my %hash;
foreach (@list) {
my ( $id, $name ) = split /\t/, $_, 2;
$name =~ s/[\\\/\<\>\?\:\|\*]/ /g;
$name =~ s/ {2,}/ /g;
$hash{$id} = $name;
}
chdir ( "./doRename/2.4" ) ;
my $source = `dir /b`;
my @src = split /\n/, $source;
chomp @src;
foreach my $f ( @src ) {
my @parts = split /[ _]/, $f;
print $f ;
MoveFile $f, "$hash{$parts[1]}.mp3" or print fileLastError() ; #W
+in32API::File
#moveW $f, "$hash{$parts[1]}.mp3" or print errorW; # Win32::Un
+icode::File
print $/;
}
There are 2 sample files in folder 2.4.
One will rename to a file name starts with ANSI char.
If I use the
Win32API::File way, there is no error raised, it do the rename, but it turns into monster char.
If I use the
Win32::Unicode::File way, it raised an err
Undefined subroutine Errno::ERROR_FILE_EXISTS called at C:/Perl/site/lib/Unicode/Error.pm line 31.
The other will rename to a pure Japanese file name.
If I use the Win32API::File way, it rasied an err : The filename, directory name, or volume label syntax is incorrect
If use the Win32::Unicode::File way, it does nothing, no err, and no rename.
Note, before I run this from my cmd prompt, I've changed codepage to 65001. Without this, the error message will raise in Chinese ( I guess ), as it showed in monster as well.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.