Fwd: how to find the drive in python/cygwin?

Ivan Van Laningham ivanlan at pauahtun.org
Tue Apr 26 21:02:48 EDT 2005


Hi All--
Use win32api to find drives:

====cut here====
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import os.path
import win32api
import sys


def findAllDrives():
    Drives=[]
    print "Searching for drives..."
    drives=win32api.GetLogicalDriveStrings().split(":")
    for i in drives:
        dr=i[-1].lower()
        if dr.isalpha():
            dr+=":\\"
            inf=None
            try:
                inf=win32api.GetVolumeInformation(dr)
            except:
                pass # Removable drive, not ready
		     # You'll still get the drive letter, but inf will be None
            Drives.append([dr,inf])
    return Drives

if __name__=="__main__":
    drives=findAllDrives()
    for i in drives:
        print i[0],i[1]

====cut here====

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours



More information about the Python-list mailing list