Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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 ?


Replies are listed 'Best First'.
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.

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://384226]
Approved by tomhukins
What's the matter? Cat got your tongue?...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-05-20 22:09 GMT
Find Nodes?
    Voting Booth?