Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

1 view
Skip to first unread message

willgun

unread,
Jun 15, 2009, 8:58:55 AM6/15/09
to
Hi,everyone!

How to get the total size of a local hard disk?
I mean total size,not free space.

Thanks in advance!

Paul Boddie

unread,
Jun 15, 2009, 9:48:17 AM6/15/09
to
On 15 Jun, 14:58, willgun <will...@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.

Paul

willgun

unread,
Jun 15, 2009, 9:53:17 AM6/15/09
to
Unfortunately,I'm on win32.
Actually,I prefer a cross-platform method.
Thanks.

Tim Golden

unread,
Jun 15, 2009, 9:53:57 AM6/15/09
to pytho...@python.org


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

Tim Golden

unread,
Jun 15, 2009, 10:04:08 AM6/15/09
to pytho...@python.org

These kind of things tend to be fairly platform specific.
Obviously, nothing's stopping anyone writing a module
which does some platform-sniffing
and conditional imports and provides a consistent
interface. Far as I know, though, there's no such thing
for Python at the mo. Think of it as a market opportunity!

TJG

Tim Harig

unread,
Jun 15, 2009, 11:40:53 AM6/15/09
to
On 2009-06-15, Tim Golden <ma...@timgolden.me.uk> wrote:
> These kind of things tend to be fairly platform specific.

There is however a way to do it in a cross platform manner which will
return an appoximation of the available space.

1. delete all of the files (and folders) on the partition that you want to
test.

2. create a file as large as the drive will permit.

3. repeat two with as many files as the drive will allow to be written.
This needs to be done on filesystems with file size limits (ie,
FAT file systems will only allow files as large as 4G).

4. Once all the files have been written, calculate the total size of all of
the files to get your answer.

This method is a little descructive and slow; but, it should work on
all platforms.

<warning font="small print">
This is a joke. Do not take it seriously. I do not actually suggest
anybody use this method to measure the size of their drive. I do not take any
responsibility for any damages incurred by using this method. I will laugh
at you if you do. Offer not valid in AK, HI, Puero Rico, or U.S Virgin Ilands.
</warning>

Nigel Rantor

unread,
Jun 16, 2009, 12:50:48 PM6/16/09
to Tim Harig, pytho...@python.org
Tim Harig wrote:
> <warning font="small print">
> This is a joke. Do not take it seriously. I do not actually suggest
> anybody use this method to measure the size of their drive. I do not take any
> responsibility for any damages incurred by using this method. I will laugh
> at you if you do. Offer not valid in AK, HI, Puero Rico, or U.S Virgin Ilands.
> </warning>

Like most jokes it's not really funny if you have to explain it.

But I appreciate that you're worried that anyone who would actually
follow the advice would also probably be rabidly litigious even if they
were one of those rare-breed of living brain-donors.

n

Tim Roberts

unread,
Jun 17, 2009, 2:18:29 AM6/17/09
to
willgun <wil...@live.cn> wrote:
>
>Unfortunately,I'm on win32.
>Actually,I prefer a cross-platform method.

Why do you need this? This kind of information is not very useful in a
cross-platform application.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

0 new messages