drives in a file chooser

Matt Setzer dontspamsetzer at nwlink.com
Mon Apr 30 01:21:50 EDT 2001


    I don't think there's a way to do it from the os module, but if you've
got the win32 extensions installed this should do it :

from win32file import GetLogicalDrives

def GetDrives() :
    "Returns a list of valid drives on this system, in order"
    drives = []
    driveMask = GetLogicalDrives()
    for i in range( 0, 31 ) :
        if driveMask & ( 1 << i ) :
            drives.append( chr( ord( 'a' ) + i ) )

    return drives

Matt Setzer

"Volucris" <volucris at hotmail.com> wrote in message
news:3aecd342$0$39601$6e49188b at news.goldengate.net...
> Is there a way to get a list of the drives available (on win32: c:, a:,
b:,
> d:, etc.)? Ultimately, I want to make a file chooser in a Tkinter app.
> Desperatly I tried
>
>     os.listdir(os.path.abspath('c:\\..'))
>
> but that does nothing useful. Otherwise, I could just confine my users to
a
> single drive and say it's a security feature.
>
> greg
>
>





More information about the Python-list mailing list