how on earth do i get a drive list?

Peter Hansen peter at engcorp.com
Thu Jul 26 21:12:32 EDT 2001


David Bolen wrote:
> The simplest method is via the win32api module:
> 
>     >>> import win32api
>     >>> import string
>     >>> string.split(win32api.GetLogicalDriveStrings(),'\0')[:-1]
>     ['A:\\', 'C:\\', 'D:\\', 'E:\\']

Nice to see that even with something as platform-dependent
and non-core as this, the "one obvious way to do it" 
claim holds up well. :-)

I'm curious why mine[**] returns lower-case results while
yours gives upper case.  I'm on Windows 98 first release,
running from the DOS prompt.  Is even this trivial thing
inconsistent across different versions of the Win32 API?!

----

[**] from my answer to the question:
>>> import win32api
>>> drives = win32api.GetLogicalDriveStrings()
>>> drives
'a:\\\x00c:\\\x00d:\\\x00e:\\\x00v:\\\x00'
>>> drives.split('\x00')[:-1]
['a:\\', 'c:\\', 'd:\\', 'e:\\', 'v:\\']

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list