If your need is to total the size of an entire drive, then using
my @info = Win32::DriveInfo::DriveSpace( 'C' );
printf 'Total:%11d Used:%11d Free: %11d',
$info[5], $info[5]-$info[6], $info[6];
Total: 1076027392 Used: 1040338944 Free: 35688448
will return the same numbers as displayed on the properties tab for the specified drive in W.Explorer. This appears to be almost instantaneous.
However, if you need to find the size of a subdir tree, then the quickest way is to use Win32::OLE to access the Scripting.FileSystemObject (assuming you have this installed).
#! perl -sw
use strict;
use Win32::OLE;
my $fs = Win32::OLE->CreateObject('Scripting.FileSystemObject');
my $folder = $fs->GetFolder('e:/perl');
print 'e:\perl: ', $folder->size(), ' used', $/;
e:\perl: 52488590 used
This still needs to recurse the subdirs, but as it is done from within the OS in C, unsurprisingly it is considerably faster than you can do it yourself from Perl.
One further advantage of using the FileSystemObject is that subsequent calls to the size() function will reflect any changes to the folder or subtree without needing to re-calculate the numbers from scratch.
You could also look at the Win32::ChangeNotify API for a method of quickly discovering if any changes have occured in that part of the filesystem you are interested in. The changes that can be monotored include, file/directory names, sizes, attributes, security descriptors, and timestamps.
Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work. |