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

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.

      --
      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.