It'll find the total size of the folder very quickly (useful by itself), then iterates through the files. Error handling not included ;)
#!perl -l use warnings; use strict; use Win32::OLE qw/in/; die "Usage: $0 [dir]" unless (!@ARGV || -d $ARGV[0]); my $fs = Win32::OLE->CreateObject('Scripting.FileSystemObject'); my ($count, $maxname); my $max = 0; my $dir = shift || 'c:/temp'; my $fold = $fs->GetFolder($dir); print $fold->Size(), " total bytes used"; folders( $dir ); print "$count total files, $maxname = $max"; sub folders { my $dir = shift; my $fold = $fs->GetFolder( $dir ); foreach my $file ( in $fold->Files ) { my $size = $file->Size(); if ( $size > $max ) { $max = $size; $maxname = $file->Name; } $count++; } foreach my $subdir ( in $fold->SubFolders ) { folders( $subdir ); } }
In reply to Re: Get the Total Size & Total Files in a Directory
by bmann
in thread Get the Total Size & Total Files in a Directory
by gopalr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |