in reply to API Calls from Perl

If you want to make the direct API call, use Win32::API (but look below for an easier method). You can get it from CPAN, or via PPM if you're using ActivePerl from ActiveState, or from the author's site at http://dada.perl.it/ Here's some (tested locally) code that uses the API calls. I retrived the base for this code from a posting to the ActiveState Perl Mailing list by Bill Luebkert:
use strict; use Win32::API; my $v = 0; # set to 1 for verbose sub DRIVE_UNKNOWN { 0; } # The drive type cannot be determined. sub DRIVE_NO_ROOT_DIR { 1; } # The root directory does not exist. sub DRIVE_REMOVABLE { 2; } # The drive can be removed from the driv +e. sub DRIVE_FIXED { 3; } # The disk cannot be removed from the dr +ive. sub DRIVE_REMOTE { 4; } # The drive is a remote (network) drive +. sub DRIVE_CDROM { 5; } # The drive is a CD-ROM drive. sub DRIVE_RAMDISK { 6; } # The drive is a RAM disk. my $GetDriveType = new Win32::API("kernel32", "GetDriveType", ['P'], ' +N') or die Win32::FormatMessage(Win32::GetLastError()); my $GetDiskFreeSpace = new Win32::API("kernel32", "GetDiskFreeSpace", +['P','P','P','P','P'], 'N') or die Win32::FormatMessage(Win32::GetLas +tError()); open (BADLIST, "chk_servers") or die; while (<BADLIST>) { chomp; #my ($server,$nos,$domain,$share1,$share2)=split(/,/); #my (undef, $server, $share) = split /\\+/; #print "Share $share on $server\n"; my $Drive = $_; print "$Drive: "; my $ret = $GetDriveType->Call($Drive) or die Win32::FormatMessage( +Win32::GetLastError()); if ($ret == DRIVE_CDROM) { print "$_: CD-ROM\n"; next; } next if ($ret == DRIVE_UNKNOWN); #next if ($ret == DRIVE_NO_ROOT_DIR); if ($ret == DRIVE_REMOVABLE) { print "$_: Removeable\n"; next; +} #if ($ret == DRIVE_REMOTE) { print "$_: Network\n"; next; } $Drive = "$_\0"; #my $Drive = "\\\\$server\\$share1\$\\\0"; my $SecsPerCluster = pack ("I", 0); my $BytesPerSec = pack ("I", 0); my $FreeClusters = pack ("I", 0); my $TotClusters = pack ("I", 0); $ret = $GetDiskFreeSpace->Call($Drive, $SecsPerCluster, $BytesPerS +ec, $FreeClusters, $TotClusters) or print Win32::FormatMessage(Win32: +:GetLastError()); my $SPC = unpack ("I", $SecsPerCluster); my $BPS = unpack ("I", $BytesPerSec); my $FC = unpack ("I", $FreeClusters); my $TC = unpack ("I", $TotClusters); if ($ret) { printf "%-2.2s %9.3f\n\tSecsPerCluster=%u\n\tBytesPerSec=%u\n" +, $Drive, $SPC * $BPS * $FC / (1024 * 1024), $SPC, $BPS if $v; printf "\tFreeClusters=%u\n\tTotClusters=%u\n", $FC, $TC if $v +; printf "%9.0f Bytes\n", $SPC * $BPS * $FC ; } }
BUT -- all this is a mistake in my opinion (although very educational about making these calls). Use either Win32::AdminMisc from Dave Roth or Win32::DriveInfo, so that all the above gets culled to a line like:         if (my (undef, undef, undef, undef, undef, $totalbytes, $freebytes) = Win32::DriveInfo::DriveSpace($UNC)) Both are in PPM and CPAN.
----Asim, known to some as Woodrow.