views:

50

answers:

1

I am trying to list the disk drives that a system may have.

On Windows, it may be something like "C:/", "D:/", "E:/".

On Linux, it may be something like "/boot", "/media/SDCard", etc.

And I don't know what it's like on a Mac. Maybe something under /Volumes.

Does anyone know of a cross platform way (that is, one which works on Linux, Windows and Mac) in Python?

Thanks!

Oh: a quick note, I am running Python 2.6.

+2  A: 

There isn't really a unified naming scheme for Linux devices that guarantees you a formatable block device. There are conventions, but they can vary widely and I can call my thumb-drive /Thomas/O if I want and there is no cross-platform way in Python to know:

  1. That /Thomas/O corresponds to /dev/sdf1
  2. That /dev/sdf1 can have a FAT32 filesystem made on it
  3. That /dev/sdf is not preferred to /dev/sdf1

I'm pretty sure that neither is there a cross-platform Python module which will allow you to determine that H:/ is formattable on a Windows system but that Z:/ is not.

Each system will require its own specific checks and validations which you could best learn from studying open-source disk manipulation software.

msw
I was thinking of how a program like gparted does it. But, that is not cross platform, only Unix (or even Linux), right?The drives do not necessarily have to be formattable. Just, they should be attached or internal media. As I'm mostly dealing with SD cards, I'm just listing /media under Linux, /Volumes on Mac, and all disk drives (C:/, D:/ etc.) on Windows.
Thomas O
Don't ponder it, steal it. The ideas, I mean, but the source too, unless you like reinventing wheels. http://sourceforge.net/projects/gparted/files/gparted/
msw
And there is no guarantee at all that /media will even exist on Linux or that an unformatted drive will be mounted for you to see. Even NT/Vista/7 allows mounting a device on an arbitrary directory in the Unixy way.
msw