in reply to Re: Windows Scriptin Host & OLE.
in thread Windows Scriptin Host & OLE.

$fcount return the number of files very nicely, but I couldn't see how I can return the number of folders. If I use the code supplied by bbfu
my $file_count = $folder->Files()->Count(); my $folder_count = $folder->SubFolders()->Count(); my $total = $file_count + $folder_count; print "$file_count $folder_count $total \n";
the results are not accurate because it only scans the top level of the path supplied!

Do I need to recurs into every sub folder to get the number of folders or is there away that I can obtain the total number of folders (folders + subfolders) with this method?,...I am sure there is but the results I am getting are inaccurate....Your help is highly appreciated now I am so near finishing this thing off for good.

Thanks Guys

Replies are listed 'Best First'.
Re: Re: Re: Windows Scriptin Host & OLE.
by blackadder (Hermit) on Jul 28, 2003 at 12:30 UTC
    Ignore my previous post PLease....

    It was too simple I just needed to read your codes a little bit closer, Below is how I did it, it seems to be working

    Thanking you all.
    AUTOLOAD; require 5.006; $|++; use strict; use warnings 'all'; use diagnostics; use Win32::OLE qw[in]; my $fso = Win32::OLE->new( 'Scripting.FileSystemObject' ); my @folders = $fso->GetFolder( $ARGV[0] ); my $fCount =0; my $sCount =0; while( @folders ) { my $folder = pop @folders; $fCount += $folder->Files->Count; $sCount += $folder->SubFolders->Count; for my $subFolder ( in $folder->SubFolders ) { $fCount += $subFolder->Files->Count; push @folders, $_ for in $subFolder->SubFolders ; $sCount += $subFolder->SubFolders->Count; } } print "Files : $fCount, folders : $sCount\n";
    Aaaaouch, Lost a point and that really hurts...Well losing points here on PerlMonks is helping me to be less lazy...

    Great Spirits have always encountered violent opposition from mediocre minds. ******************************************************************