Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: rename to UTF8 filename

by exilepanda (Monk)
on Jul 30, 2012 at 08:37 UTC ( #984390=note: print w/ replies, xml ) Need Help??


in reply to Re^3: rename to UTF8 filename
in thread rename to UTF8 filename

.. 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.... as it showed in monster as well.

???

It's because my origional work is reading the list from an Excel file

Thanks, but Sorry won't work for me. ERRRR(2)(No such file or directory)(2)(The system cannot find the file specified) at test6.pl line 25.

Where Ln 25 is  open my($fh), '<:encoding(UTF-8)', $names or die sprintf q/ERRRR(%d)(%s)(%d)(%s)/, $!,$!,$^E,$^E;

I've check against the output, folder fafafa is built correct, as well the content in utfnamelist.txt. It's just won't do the rest. Anywhere I can further check with ?


Comment on Re^4: rename to UTF8 filename
Select or Download Code
Re^5: rename to UTF8 filename
by Anonymous Monk on Jul 30, 2012 at 08:40 UTC

    Sorry but won't work for me. .... Anywhere I can further check with ?

    I don't know, you've just described an impossible situation

Re^5: rename to UTF8 filename
by Anonymous Monk on Jul 30, 2012 at 09:36 UTC

    Bah! sorry about that ( a bug, the program relied on a pre-existing utfnamelist.txt ), try this

    #!/usr/bin/perl -- use strict; use warnings; use Path::Class; use File::Slurp; use Data::Dump; use Win32::Unicode::File; our $thisf = file(__FILE__)->absolute; our $thisd = $thisf->dir; our $tmp = 'fafafa'; chdir $thisd or die sprintf q/ERRRR(%d)(%s)(%d)(%s)/, $!,$!,$^E,$^E; mkdir $tmp or die sprintf q/ERRRR(%d)(%s)(%d)(%s)/, $!,$!,$^E,$^E; chdir $tmp or die sprintf q/ERRRR(%d)(%s)(%d)(%s)/, $!,$!,$^E,$^E; my $names = file('utfnamelist.txt')->absolute; #~ my $bin = read_file( $names, { binmode => ':raw' } ) ; dd $bin; my $bin = "\xEF\xBB\xBF# a utf-8 file-o kebab's\r\nutfnamelist.txt +\xD1\x9B\xD0\xB5\xD0\xB2\xD0\xB0\xD0\xBF.txt\r\n\xD1\x9B\xD0\xB5\xD0\ +xB2\xD0\xB0\xD0\xBF.txt ra\xC5\xBEnji\xC4\x87.txt\r\nra\xC5\ +xBEnji\xC4\x87.txt \xC4\x87evap.txt\r\n\xC4\x87evap.txt + \xD0\xBA\xD0\xB5\xD0\xB1\xD0\xB0\xD0\xBF\xD1\x87\xD0\xB5.txt\r\n\x +D0\xBA\xD0\xB5\xD0\xB1\xD0\xB0\xD0\xBF\xD1\x87\xD0\xB5.txt keb +abNOMORE.txt\r\n"; write_file( $names->basename, \$bin ); binmode STDOUT, ':encoding(UTF-8)';print "\x{feff}";#BOM ddir(); open my($fh), '<:encoding(UTF-8)', \$bin or die sprintf q/ERRRR(%d)(%s +)(%d)(%s)/, $!,$!,$^E,$^E; while(<$fh>){ next if $. == 1; # /#/; my( $here, $there ) = split /\s+/, $_; next unless $here and $there; print "# moveW $here => $there\n"; #~ dd [ $here, $there ]; moveW( $here, $there ) or die sprintf q/ERRRR(%d)(%s)(%d)(%s)/, $ +!,$!,$^E,$^E; ddir(); } chdir '..'; dir($tmp)->rmtree("verbose","cautious"); sub ddir { my $dir = `cmd /x /c "dir /b "`;; #~ use Encode::Detective qw' detect '; #~ warn detect($dir) ; # "UTF-8" utf8::decode($dir); print "# dir # ", $dir ; }
      Thanks Man! It works now, and inspires a lot! I found I have 2 problem here.

      1. If I don't use Path::Class, Win32::Unicode::File cannot survive on it's own. It ends up with Undefined subroutine.... when I call moveW()( How do you know that?? ). And I found the errorW(), dieW() won't work at all. Not sure if I missed something when I download this module via ppm.

      2. I forgot the BOM char in my text list. It ends up by messing the file name and so File not found. After adding read ( F, $_, 1 ), then start to read. It reads correctly and moveW works!

      But then, would you point out where absolute() and basename() method import from? I can't find it in the perldoc where the modules you used.

      Anyway, thank you very much!

        If I don't use Path::Class, Win32::Unicode::File cannot survive on it's own. It ends up with Undefined subroutine.... when I call moveW()( How do you know that?? ).

        What does that mean?

        $ perl -E " use Win32::Unicode::File; use Data::Dump; dd \@Win32::Unic +ode::File::EXPORT, \&moveW ; moveW()" ( [ "file_type", "file_size", "copyW", "moveW", "unlinkW", "touchW", "renameW", "statW", "utimeW", ], sub { ... }, ) Usage: moveW(from, to [, over]) at -e line 1.

        And I found the errorW(), dieW() won't work at all. Not sure if I missed something when I download this module via ppm.

        You sure?

        $ perl -E " use Win32::Unicode; use Data::Dump; errorW(); dd [ $@, er +rorW() ]; eval { moveW() }; dd [ $@, errorW()]; eval { moveW(qw{ . . + }) }; dd[$@, errorW()]; dieW 666;" ["", "The handle is invalid."] [ "Usage: moveW(from, to [, over]) at -e line 1.\n", "The handle is invalid.", ] ["", "The handle is invalid."] 666 at -e line 1.

        But then, would you point out where absolute() and basename() method import from? I can't find it in the perldoc where the modules you used.

        Path::Class gives you Path::Class::File and Path::Class::Dir objects

        $ perl -MPath::Class -E " say file(1) " 1 $ perl -MPath::Class -E " say ref file(1) " Path::Class::File $ perl -MPath::Class -MData::Dump -E " dd file(1) " bless({ dir => undef, file => 1, file_spec_class => undef }, "Path::Cl +ass::File") $ perl -MPath::Class -E " say file(1)->basename " 1 $

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://984390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-12-21 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls