http://qs1969.pair.com?node_id=266793

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

Dear Monks, I used the following code to obtain share information off a remote NT server (shares are always directory or a folder).
if (Win32::Lanman::NetShareEnum($_, \ my @ShareList)) { foreach my $Share (@ShareList) { my ($Remark, $Path, $NetName); $NetName = $Share->{netname}; if("" ne $Share->{Remark}) {$Remark="($Share->{remark})";} if("" ne $Share->{path}) {$Path=$Share->{path};} else {$Path="No Permission to display";} push (my @ShareList, name=>$NetName, remark=>$Remark, path=>$Path}); foreach my $Item (@ShareList) { print "\n$Item->{name}"; print "\t$Item->{path}"; print "\t$Item->{remark}"; } } }
Now I need to also obtain the size of the share. Any perls of wisdom will be highly appreciated Blackadder

Replies are listed 'Best First'.
Re: How to obtain the size of a remote Winnt4 share
by benn (Vicar) on Jun 18, 2003 at 12:26 UTC
    A quick CPAN search reveals Win32DriveInfo...
    use Win32::DriveInfo; ($SectorsPerCluster, $BytesPerSector, $NumberOfFreeClusters, $TotalNumberOfClusters, $FreeBytesAvailableToCaller, $TotalNumberOfBytes, $TotalNumberOfFreeBytes) = Win32::DriveInfo::DriveSpace("\\\\serv +\\share"));
    Cheers, Ben.
Re: How to obtain the size of a remote Winnt4 share
by Asim (Hermit) on Jun 18, 2003 at 12:01 UTC

    *EDITED to fix File::Find error...*

    The two ways that leap to mind are:

    1. Iterate through the share with File::Find, using the -s test to grab each file's size (I found I had to use Math::BigInt on the size counter as well, your milage may vary.
    2. Use Win32::DirSize to do the job; it's easier but you lose a level of control, and I found it slow.
    3. Does that help? I can post sample code for both, but the docs on all these modules have good usage information.

      ----Asim, known to some as Woodrow.

        Indeed, I did, and I have corrected it.
        Thanks for the heads-up!

        ----Asim, known to some as Woodrow.

Re: How to obtain the size of a remote Winnt4 share
by wufnik (Friar) on Jun 18, 2003 at 13:19 UTC
    hola;

    Asim mentioned earlier the module win32::Dirsize, which copes well with the size problems one can often encounter (witness his use of bigint) in determining the size of remote directories. though he says it is slow, it is certainly faster than summing file sizes via file::find.

    here is a scriptlet which demonstrates its use.

    use Win32::DirSize; chomp(my $dir = shift || <DATA>); my @dirstats; push @dirstats,sprintf("%-40s%-10s%-10s%-10s\n", "Directory", "Size", "FileCount", "DirCount"); if (dir_size($dir, my $dirstat) == DS_RESULT_OK){ my $size = best_convert(my $unit, $dirstat->{HighSize}, $dirstat->{LowSize}); my $filecount = $dirstat->{FileCount}; my $dircount = $dirstat->{DirCount}; push @dirstats, sprintf("%-40s%-10s%-10s%-10s\n", $dir, sprintf("%8.4f", $size) . $unit, $filecount, $dircount); } push @dirstats, undef; map { print } grep { defined } @dirstats; __DATA__ \\save\farscape$\warez
    which produces something like
    Directory Size FileCount DirCount \\save\farscape$\warez 717.0521M 4435 999
    hope that helps. yes, it uses map in a void context, but i cannot resist map's allure.

    ...wufnik

    -- in the world of the mules there are no rules --