Using a CPAN module is the recommended way to go, as indicated by the responses above. It's also possible to solve this problem by going directly to the Win32 API, for example:

use Win32::API; sub make_large_int { my ($lo, $hi) = @_; return $hi * (1 + 0xffffffff) + $lo; } # Return a two-element list: (size, free) in bytes. sub win_get_disk_free { my $dir = shift; # $dir is a directory on the disk of interest $dir =~ tr{/}{\\}; my $GetDiskFreeSpaceEx = Win32::API->new( 'kernel32.dll', 'GetDiskFreeSpaceEx', ['P','P','P','P'], 'I') or die; my $lpFreeBytesAvailable = pack('L2', 0, 0); my $lpTotalNumberOfBytes = pack('L2', 0, 0); my $lpTotalNumberOfFreeBytes = pack('L2', 0, 0); $GetDiskFreeSpaceEx->Call($dir, $lpFreeBytesAvailable, $lpTotalNumberOfBytes, $lpTotalNumberOfFreeBytes) or die "GetDiskFreeSpaceEx failed ($^E)\n"; return ( make_large_int(unpack('L2', $lpTotalNumberOfBytes)), make_large_int(unpack('L2', $lpTotalNumberOfFreeBytes)) ); } my ($size, $free) = win_get_disk_free('C:/'); printf "disk size = %d MB\n", $size/(1024*1024); printf "disk free = %d MB\n", $free/(1024*1024);


In reply to Re: hard drive space by eyepopslikeamosquito
in thread hard drive space by Anonymous Monk

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.