Win32 Drive List Redux

Thomas Heller theller at python.net
Thu Jan 2 14:34:15 EST 2003


Tim Daneliuk <tundra at tundraware.com> writes:

> 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:
> 
> win32api.GetLogicalDriveStrings()
> 
> 
> And Ken Seehof suggested:
> 
> def drives():
>      d = []
>      for c in string.lowercase:
>          if os.path.exists('%s:/'%c):
>              d.append('%s:'%c)
>      return d
> 
> 
> In my application, the first solution is not practical because I cannot
> gurantee the user will have win32api (win32all) installed.

ctypes may be small enough so that you can redistribute it
with your app. With ctypes you would write:

----
from ctypes import windll, c_string

size = windll.kernel32.GetLogicalDriveStringsA(0, None)
s = c_string('\000' * size)
size = windll.kernel32.GetLogicalDriveStringsA(len(s), s)
print s.raw[:size]
----

Available at http://starship.python.net/crew/theller/ctypes.html

Thomas




More information about the Python-list mailing list