Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Find A Share size in Win2k

by BrowserUk (Patriarch)
on Oct 10, 2002 at 20:42 UTC ( #204317=note: print w/replies, xml ) Need Help??


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!

Replies are listed 'Best First'.
Re: Re: Find A Share size in Win2k
by jsprat (Curate) on Oct 10, 2002 at 21:14 UTC
    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.
    Good catch, BrowserUK. This would've bit Ozzy for sure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://204317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2022-10-04 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (19 votes). Check out past polls.

    Notices?