blackadder has asked for the wisdom of the Perl Monks concerning the following question:

How can I adapt this bit of code;
my $size = 0; $size += (-f $_ ? -s _ : 0) for (<*>); print $size;
so that instead of <*> i can pass on a remote share or directory name?

like this: \\Server\Share_Name or \\Server\DriveLetter\FolderName.

Since I have not tried this code yet so I don't know how fast it is, but I have tried these 2 methods

1) ($Total)=( (qx{dir /s "$UncSharePath"})[-2]=~ /([\d,]+) bytes/ ) 2) find(sub { $total += -s }, $dir);
And they are very slow -unusable really in real life, ok on small servers thu.
Does any one know how can I extract the sizes of a remote share or folder directly off the OS? Surely automating this process in Perl should be faster than doing it manually, i.e. by right clicking on a folder and selecting the properties, which seems to be the fastest method, but unfortunaly I have a list of servers to go through...
Thanks for your help Guys.

Replies are listed 'Best First'.
Re: Faster way to obtain a remote share or folder size
by BrowserUk (Patriarch) on Jul 01, 2003 at 16:42 UTC

    Take a look at this thread Find A Share size in Win2k. There is a method there by jsprat that is blindingly fast if the shared directory is the root of the remote drive.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Re: Faster way to obtain a remote share or folder size
by TomDLux (Vicar) on Jul 01, 2003 at 16:55 UTC

    Your headline asks for a faster way, but the message asks how you can get the size of a directory other than the one where you are.

    Of course, I'm writing on Linux, but the routine should work on all platforms.

    my $dirname = "/usr/local/bin"; my $size = get_dir_size( $dirname ); # Perl Cookbook recipe 9.5 # sub get_dir_size { return unless @_ && -e $_[0] && -d _ && -r _ ; my ( $dir ) = @_; my ( $file, $size ); opendir DIR, $dir or die( "Could not open directory '$dir'\n" ); while ( defined ( $file = readdir( DIR ))) { $size += -s "$dir/$file"; } closedir DIR; return $size; }

    Of course, the easy answer, especially if you're interested in subdirectories, too, is:

    $size = `du -s -k $dir`;

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

      Thanks guys, I 'll try out your suggestions...

      And I'll try and be more precise with wording of my posts :)

      Cheers.