For unicode filenames on windows you need to use Win32::Unicode
update: Example #!/usr/bin/perl --
use strict;
use warnings;
use Win32::Unicode -native;
listDir();
open my($fh), '>:encoding(UTF-8)', qq{I-\x{2665}-Perl} or die $!;
print $fh qq{I-\x{2665}-Perl};
close $fh;
listDir();
rename qq{I-\x{2665}-Perl}, 'I-love-Perl';
listDir();
unlink 'I-love-Perl';
sub listDir {
my( $dir ) = grep defined, @_, '.';
my $wdir = Win32::Unicode::Dir->new( );
$wdir->open($dir) or die $!;
for ($wdir->fetch) {
next if /^\.{1,2}$/;
my $full_path = "$dir/$_";
if (file_type('f', $full_path)) {
print "f $_\n";
}
elsif (file_type('d', $full_path)){
print "d $_\n";
}
}
$wdir->close or die $!;
print "\n####\n\n";
}
__END__
$ chcp 65001
Active code page: 65001
$ perl win32-unicode-native-to-ascii.pl
f win32-unicode-native-to-ascii.pl
####
f I-♥-Perl
f win32-unicode-native-to-ascii.pl
####
f I-love-Perl
f win32-unicode-native-to-ascii.pl
####
$
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|