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

Finding mountpoints in windows

38 views
Skip to first unread message

Stephen Boulet

unread,
Jan 15, 2002, 11:01:06 AM1/15/02
to
I see that I can use os.chdir to get from, say, N: to C:. Is there a way
to list the mountpoints if I can't assume what they are beforehand?

Thanks.

-- Stephen

Simon Brunning

unread,
Jan 15, 2002, 11:30:21 AM1/15/02
to
> From: Stephen Boulet [SMTP:stephen...@motorola.com]

> I see that I can use os.chdir to get from, say, N: to C:. Is there a way
> to list the mountpoints if I can't assume what they are beforehand?

You'll need win32all. Then you use:

import win32api, win32file

drives = [drive for drive in
win32api.GetLogicalDriveStrings().split('\x00')[:-1] if
win32file.GetDriveType(drive) == win32file.DRIVE_FIXED]

Cheers,
Simon Brunning
TriSystems Ltd.
sbru...@trisystems.co.uk


-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.

Simon Brunning

unread,
Jan 15, 2002, 11:39:48 AM1/15/02
to
> From: Simon Brunning
> From: Stephen Boulet [SMTP:stephen...@motorola.com]
> I see that I can use os.chdir to get from, say, N: to C:. Is there a
> way
> to list the mountpoints if I can't assume what they are beforehand?
>
> You'll need win32all. Then you use:
>
> import win32api, win32file
>
> drives = [drive for drive in
> win32api.GetLogicalDriveStrings().split('\x00')[:-1] if
> win32file.GetDriveType(drive) == win32file.DRIVE_FIXED]

Woops! This will only get you the local hard drives. You'll need to look at
the win32file.DRIVE_whatever values to see which ones you want:

* win32file.DRIVE_CDROM
* win32file.DRIVE_FIXED
* win32file.DRIVE_NO_ROOT_DIR
* win32file.DRIVE_RAMDISK
* win32file.DRIVE_REMOTE
* win32file.DRIVE_REMOVABLE
* win32file.DRIVE_UNKNOWN

So if you wanted to see *all* local drives, including CD-ROMs, floppies and
so on, for example, you'd use:

drives = [drive for drive in
win32api.GetLogicalDriveStrings().split('\x00')[:-1] if

win32file.GetDriveType(drive) in [win32file.DRIVE_FIXED,
win32file.DRIVE_CDROM, win32file.DRIVE_REMOVABLE]]

Enjoy.

0 new messages