There are several sites on the web that have documentation on the WSH/FSO. The best one in terms of easy reference I found is FSO although it is a little light on worked examples.

The hardest part to wrap your brain around is how to access the elements of collections as returned by Win32::OLE. It's documentation is a little light on examples of using the in method.

In terms of your specific problem of getting a count of the files in a subtree. Unfortunately, there is no nice equivalent of the Size method that will return the count for the whole subtree, so you end up iterating the tree and totalling the file counts. Fortunately, each folder has a Count of the files it contains, so at least you dont have to iterate the files individually.

#! perl -slw use strict; use Win32::OLE qw[in]; my $fso = Win32::OLE->new( 'Scripting.FileSystemObject' ); my @folders = $fso->GetFolder( $ARGV[0] ); my $fCount =0; while( @folders ) { my $folder = pop @folders; $fCount += $folder->Files->Count; for my $subFolder ( in $folder->SubFolders ) { $fCount += $subFolder->Files->Count; push @folders, $_ for in $subFolder->SubFolders ; } } print $fCount;

Pleasingly, this renders the same answers as are shown on the Properties dialog for a subtree.

I haven't attempted to compare the performance of this with File::Find as previous attempts at this have be thwarted by the buffering issue. It seems to run fairly quickly though.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


In reply to Re: Windows Scriptin Host & OLE. by BrowserUk
in thread Windows Scriptin Host & OLE. by blackadder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.