http://qs321.pair.com?node_id=204317


in reply to Find A Share size in Win2k

This is as much a question as a statement as I don't have access to a network on which to test this properly... Perhaps someone could verify it.

There seems to be one caveat with jsprat's technique. It works brilliantly provided the share is sharing the root of the remote drive, and not some subset of it. However, if the share represents a subdir on the actual remote drive, the information returned by the GetDrive() call represents the entire drive rather than just the shared portion of it. Or at least it appears to in my tests using local shares.

There is an alternative FileSystemObject call, GetFolder()->size(), which will return the correct information, but I think that it is doing a recursive descent accumulating filesizes as it goes, and so is possibly not much quicker than using this technique in Perl.

Anyway, here are the results I got when I shared my perl directory, e:\perl as \\mymachine\perl f:

#! perl -sw use strict; use Win32::OLE; use Benchmark; my $fs = Win32::OLE->CreateObject('Scripting.FileSystemObject'); my $local = $fs->GetFolder('e:/perl'); print 'e:\perl: ', $local->size(), ' used', $/; my $f = $fs->GetFolder('f:/'); #! e:/perl shared as f: print 'f:\ (e:\perl shared as f:): ', $f->size(), ' used', $/; my $d = $fs->GetDrive('f:'); #! e:/perl shared as f: print 'f: (using GetDrive()): ', $d->{TotalSize} - $d->{FreeSpace}, " +used\n"; __DATA__ c:\test>204222 e:\perl: 52488590 used f:\ (e:\perl shared as f:): 52488590 used f: (using GetDrive()): 2614812672 used c:\test>

I was intending to try and benchmark the two methods, but it appears to cache the value after the first call and i couldn't see any simple way of clearing the cache without rebooting, so I'll leave that to Ozzy


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!