Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Win32 Unicode filenames: how to get their size ?

by olivierp (Hermit)
on Aug 19, 2004 at 09:45 UTC ( #384226=perlquestion: print w/ replies, xml ) Need Help??
olivierp has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks !
I am traversing a series of directories / subdirectories on a W2K system, and fetching the size of each file in the directory, with something like this snippet:
@filenames = grep (!/^\.\.?$/ , readdir (DIR)); closedir DIR; foreach (@filenames){ $file = "$dir$_"; $size = -s "$file"; $h{$file} = $size; }
This works fine for filenames containing ASCII / Latin1 characters, but  -s "$file" returns undef, when the filename contains Unicode chars (japanese, ukrainian, thai, etc...) which is not really useful...
I've tried adding "use utf8;" to the script, but there is no change.
Is there a way to specify which encoding to use for opendir / readdir, as with open ?

--
Olivier

Comment on Win32 Unicode filenames: how to get their size ?
Select or Download Code
Re: Win32 Unicode filenames: how to get their size ?
by PodMaster (Abbot) on Aug 19, 2004 at 09:56 UTC
      Argh !
      Thanks for the info & pointers.
      I'm building a damn slow way involving Win32::OLE & WMI, as I can force Win32::OLE to work in UTF8.,
      WMI, albeit slow, and outright not responding for a directory with ~100000 subdirs, gives me all the info I need.

      --
      Olivier
Re: Win32 Unicode filenames: how to get their size ?
by revdiablo (Prior) on Aug 19, 2004 at 16:47 UTC

    You might want to get rid of the quotes around $file in -s "$file". Unnecessary stringification can cause problems in some cases. This may not help much in your case (since $file is already the product of string variable interpolation), but it's something to keep in mind.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-11-22 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (123 votes), past polls