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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Determine volume size on Windows
by NetWallah (Canon) on Jun 15, 2004 at 23:29 UTC
    This code is a snippet of something I obtained a long time ago, from the Roth Website.
    use Win32::Lanman; use Win32::NetAdmin; ..... sub getDDInfo{ my $i = 0; my $client = $_[0]; if (!Win32::Lanman::NetServerDiskEnum("\\\\$client",\@drives)){ print "*ERROR Getting Drive Info*"; return; } print "@drives"; foreach my $drive(@drives){ $drive =~ s/\://g; @drvinfo = Win32::AdminMisc::GetDriveSpace("\\\\$client\\$driv +e\$"); for (0..1){ # Force to zero, if undefined/ defined($drvinfo[$_]) or $drvinfo[$_] = 0; } $drive->{CAPACITY} = sprintf("%5.2f",($drvinfo[0]/1073741824)) +; #Convert to GigaBytes $drive->{SPACE} = sprintf("%5.2f",($drvinfo[1]/1073741824)); $drive->{SPACE} =~ s/\s//; $drive->{CAPACITY} =~ s/\s//; unless($drive->{CAPACITY} < .01){ $drive->{PERCENT} = sprintf("%.02f",$drive->{SPACE}/$drive +->{CAPACITY}*100); } } }

    Offense, like beauty, is in the eye of the beholder, and a fantasy.
    By guaranteeing freedom of expression, the First Amendment also guarantees offense.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Determine volume size on Windows
by meetraz (Hermit) on Jun 16, 2004 at 00:29 UTC
    I recommend the Win32::DirSize module, by yours truly. It was written to calculate directory sizes, but handles whole drives as well. Here's a sample:

    use strict; use Win32::DirSize; my $DiskInfo; # this stores the disk information my $Result = disk_space( "C:", $DiskInfo, ); if ($Result == DS_RESULT_OK) { my ($DiskSizeUnit, $DiskFreeUnit, $QuotaFreeUnit); my ($ConvDiskDize, $ConvDiskFree, $ConvQuotaFree); $ConvDiskDize = best_convert( $DiskSizeUnit, $DiskInfo->{HighTotalBytes}, $DiskInfo->{LowTotalBytes}, ); $ConvDiskFree = best_convert( $DiskFreeUnit, $DiskInfo->{HighFreeBytes}, $DiskInfo->{LowFreeBytes}, ); $ConvQuotaFree = best_convert( $QuotaFreeUnit, $DiskInfo->{HighQuotaBytes}, $DiskInfo->{LowQuotaBytes}, ); print "Disk Size = $ConvDiskDize $DiskSizeUnit \n"; print "Disk Free = $ConvDiskFree $DiskFreeUnit \n"; print "Quota Free = $ConvQuotaFree $QuotaFreeUnit \n"; }
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re:Determine volume size on Windows
by blueAdept (Beadle) on Jun 16, 2004 at 18:03 UTC
    By all means let me write your code for you..
    print "Free space: " . (split(/\s+/, qx(dir c: | find /I "bytes free") +))[3]; =pod Output: Free space: 29,143,982,080 =cut
    more seriously 'perldoc Win32::Perflib' is a viable means of getting aproximately what you ask.

    Update: read too quickly, you wanted total drive space. Can still be calculated indirectly using the perflib, but I guess the backticks example is bad.