Listing partitions (on win32)

Bengt Richter bokr at oz.net
Sun Jan 15 03:15:45 EST 2006


On 14 Jan 2006 16:52:33 -0800, "Claude Henchoz" <claude.henchoz at gmail.com> wrote:

>Hi
>
>Is there any way of listing partitions on a (win32) computer without
>using WMI?
>
Maybe this will work (I skipped A: and B:, but you can include them if
you want to catch floppy drives with something in them). The 'xxx' is just so as
not to get a full directory's worth of useless text. If xxx happens to be defined
it doesn't hurt anything. It's not going to be as fast as using one of the
win32 api packages to get at GetLogicalDriveStrings, but this works on my NT4:
(error messages apparently go to stderr, so stdout gets '' which makes the if fail)

 >>> def fakeGetLogicalDriveStrings():
 ...     return [c+':' for c in (chr(n) for n in xrange(ord('A'), ord('Z')+1))
 ...                   if os.popen('dir %s:\\xxx'%c).read()]
 ...
 >>> fakeGetLogicalDriveStrings()
 ['C:', 'D:', 'E:', 'V:', 'W:']

Regards,
Bengt Richter



More information about the Python-list mailing list