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

enumerate windows unicode filenames

by mulchman (Novice)
on Mar 02, 2006 at 23:14 UTC ( #534087=perlquestion: print w/ replies, xml ) Need Help??
mulchman has asked for the wisdom of the Perl Monks concerning the following question:

How can I enumerate windows path\\filenames, including those in non-english languages? I can enumerate and print all the english filenames using find(\%sub, $RootDir), but the non-english filenames aren't printed. Is this a unicode handling problem?

Comment on enumerate windows unicode filenames
Re: enumerate windows unicode filenames
by rhesa (Vicar) on Mar 02, 2006 at 23:25 UTC
Re: enumerate windows unicode filenames
by Courage (Parson) on Mar 05, 2006 at 12:00 UTC
    In my code I solve a problem like this (this is in 5.6.1 time, now use Unicode is somewhat obsolete):
    use Win32::OLE qw(in CP_UTF8); use Win32::OLE::Const; Win32::OLE->Option(CP=>CP_UTF8); use Unicode::String qw/utf8/; my $oshell = Win32::OLE->new('Shell.Application') or die "$@"; my $f = $oshell->NameSpace(Win32::GetCwd()); print "[$f]"; my $fi = $f->Items; print $fi->Count; print "\n"; for (0 .. $fi->Count-1) { my $item = $fi->Item($_); my $name = $item->Name; my $u=utf8($name); my $s = $u->hex; $s=~s/U\+00(\w\w)/my($r,$p)=((pack 'H*',$1),$&);if($r=~m(^[()\w .;\- ++!]$)){$r}else{$p}/eg; $s=~s/(U\+[\da-f][\da-f][\da-f][\da-f])/($1)/ig; my $ren=0; $ren=1 if $s=~/U\+(?!00)/; $s=~s/[ +]//g; print "$ren|$s\n"; if($ren){$item->{Name}=$s} }

    Best regards,
    Courage, the Cowardly Dog

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://534087]
Approved by Old_Gray_Bear
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2015-05-04 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (85 votes), past polls