How to get the total size of a local hard disk?

Tim Golden mail at timgolden.me.uk
Mon Jun 15 09:53:57 EDT 2009


Paul Boddie wrote:
> On 15 Jun, 14:58, willgun <will... at live.cn> wrote:
>> How to get the total size of a local hard disk?
>> I mean total size,not free space.
> 
> Which platform are you using? On a Linux-based system you might look
> at the contents of /proc/partitions and then, presumably with Python,
> parse the contents to yield a number of blocks for the hard disk in
> question. This quantity would then be converted into a more familiar
> measure.
> 
> One might expect something like PSI to support this kind of
> activity...
> 
> http://bitbucket.org/chrismiles/psi/
> 
> ...but I think it only really provides process-related information.


On Windows, WMI is nearly always the answer to these
kind of things (altho' since WMI is nearly always a
shell around other APIs there's usually some other way).

http://timgolden.me.uk/python/wmi_cookbook.html#percentage_free

TJG



More information about the Python-list mailing list