Win32 Drive List Redux

Chris Tavares christophertavares at earthlink.net
Fri Jan 3 17:28:30 EST 2003


"Tim Daneliuk" <tundra at tundraware.com> wrote in message
news:eop2va.igo2.ln at boundary.tundraware.com...
> Tim Daneliuk wrote:
> > Some time ago, there was a brief thread on how to get a list of
> > available drives on Win32.  Peter Hansen suggested the use of:
> <SNIP>
>
> Well, here is a "Sort-Of" solution. It suffers from the fact that it is
> not in sync with reality of the machine - it reports B: on my system
> (which has none) and incorrectly shows a network drive that has been
> detatched.  Still, its kind of interesting...
>

I missed the original suggestion, but what's wrong with this:

>>> drives = []
>>> drivemask = win32file.GetLogicalDrives()
>>> for drive in range(ord("A"), ord("Z") ):
...  if drivemask & 1 != 0:
...   drives.append( chr(drive) )
...  drivemask = drivemask >> 1
...
>>> drives
['A', 'C', 'D', 'E', 'F', 'M', 'N']

-Chris







More information about the Python-list mailing list