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
|