Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: UTF-8 and readdir, etc.

by IB2017 (Pilgrim)
on Jan 31, 2018 at 18:15 UTC ( [id://1208210]=note: print w/replies, xml ) Need Help??


in reply to UTF-8 and readdir, etc.

Hello irw005. This is the subrutine I use to read the file names in a directory with unicode names (use Win32::Unicode::Dir)

sub ReadDir{ my $Directory=shift; my @Documents; print "Reading directory's content $Directory\n"; my $wdir = Win32::Unicode::Dir->new; $wdir->open($Directory) || die; for ($wdir->fetch) { next if /^\.{1,2}$/; push (@Documents, $_) } $wdir->close || dieW $wdir->error; return \@Documents; }

Replies are listed 'Best First'.
Re^2: UTF-8 and readdir, etc.
by Anonymous Monk on Jan 31, 2018 at 18:39 UTC
    use Encode::Locale (); use Encode (); opendir my $dh, '/some/dir' or die $!; while ( my $fn = readdir $dh ) { $fn = Encode::decode( locale_fs => $fn ); # $fn is just a filename as char stream (unicode) } closedir $dh;

      also instead of

      opendir my $dh, '/some/dir' or die $!;

      it's better to have

      my $dir = '/some/dir'; # unicode # get it as fs representation my $fs_dir = Encode::encode( locale_fs => $dir ); opendir my $dh, $fs_dir or die $!;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-25 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found