How to check for remaining hard drive space in Windows?

kevinliu23 kevinliu23 at gmail.com
Wed Feb 28 19:30:56 EST 2007


Hmmmm, right now...I'm doing multiplication on the index values
returned by GetDiskFreeSpace. According to the documentation...

tuple[0]: sectors per cluster
tuple[1]: number of bytes per sector
tuple[2]: total number of free clusters
tuple[3]: total number of clusters on the disk

So I'm multiplying together indices 0, 1 and 2 together to get the
amount of free space left on my hard drive in bytes. The product of
the first three indices is over 10 gigabytes and is correct according
to my calculations. Why would the documentation say it does not return
data over 2 gigabytes then? Or do you mean not over 2 gigabytes
returned for tuple[2]? I believe my tuple[2] returned a value of
2778727 bytes, which is well below the 2 gigabyte capacity.

Anyway, thanks for letting me know about GetDiskFreeSpaceEx. I will
look into this function as well.

Thanks guys!

On Feb 28, 5:08 pm, "Jerry Hill" <malaclyp... at gmail.com> wrote:
> On 2/28/07, Tim Golden <m... at timgolden.me.uk> wrote:
>
> > Well it's not often someone beats me to a WMI
> > solution :) Just to be different, you can also
> > look at the GetDiskFreeSpace function in the
> > win32api module of the pywin32 extensions.
>
> The MSDN page for that function warns:
> "The GetDiskFreeSpace function cannot report volume sizes that are
> greater than 2 gigabytes (GB). To ensure that your application works
> with large capacity hard drives, use the GetDiskFreeSpaceEx function."
>
> Make sure to keep that in mind if you're recording free disk space
> someplace, rather than just checking for enough space to do an install
> or something.
>
> --
> Jerry





More information about the Python-list mailing list