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.

In reply to Re: API Calls from Perl by Asim
in thread API Calls from Perl by Bob A,

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.