Determine if windows drive letter is hard drive or optical from python?

Discussion in 'Python' started by mh, May 27, 2005.

  1. mh

    mh Guest

    Hi Folks-

    I'm trying to do a simple emulation of unix "locate" functionality in
    python for windows.

    Problem is I don't want to crawl/index optical drives. Do any of the
    windows people out there know how I can determine:

    1. How many drives are on the system? (I could just iterate over the
    alphabet os.path.exists("%s:\\"%letter) ... is there a "windows" way of
    doing it?)

    2. More importantly for those drives that exist, how do I determine if
    it is actually a harddrive?

    thanks

    matt
    mh, May 27, 2005
    #1
    1. Advertising

  2. Hi !

    You can use WMI, for that.

    Michel Claveau
    Do Re Mi chel La Si Do, May 27, 2005
    #2
    1. Advertising

  3. "mh" <>:

    >2. More importantly for those drives that exist, how do I determine if
    >it is actually a harddrive?


    C:\>python
    Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import win32file,string
    >>> def harddisks():

    .... driveletters=[]
    .... for drive in string.letters[len(string.letters)/2:]:
    .... if win32file.GetDriveType(drive+":")==win32file.DRIVE_FIXED:
    .... driveletters.append(drive+":")
    .... return driveletters
    ....
    >>> harddisks()

    ['C:', 'F:']

    --
    Thank you for observing all safety precautions
    Wolfgang Strobl, May 28, 2005
    #3
  4. mh

    Magnus Lycka Guest

    Re: Determine if windows drive letter is hard drive or optical frompython?

    Wolfgang Strobl wrote:
    > ... for drive in string.letters[len(string.letters)/2:]:


    Or better...
    ....... for drive in string.ascii_uppercase:

    string.letters differ with locale, but Windows drives are always
    only A-Z (right?) and just iterating over upper case (or lower)
    seems more clear than to iterate over half of the sum of both...
    Magnus Lycka, May 30, 2005
    #4
  5. Magnus Lycka <>:

    >Wolfgang Strobl wrote:
    >> ... for drive in string.letters[len(string.letters)/2:]:

    >
    >Or better...
    >...... for drive in string.ascii_uppercase:
    >
    >string.letters differ with locale, but Windows drives are always
    >only A-Z (right?) and just iterating over upper case (or lower)
    >seems more clear than to iterate over half of the sum of both...


    Ooops. Your're right, of course. In my defense, I could argue that it
    was a cut&paste job, from a program written long ago ...

    --
    Thank you for observing all safety precautions
    Wolfgang Strobl, May 31, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vertigo

    big letter -> small letter

    vertigo, Jul 6, 2004, in forum: Python
    Replies:
    4
    Views:
    753
    Reinhold Birkenfeld
    Jul 6, 2004
  2. Tony Meyer

    RE: big letter -> small letter

    Tony Meyer, Jul 6, 2004, in forum: Python
    Replies:
    0
    Views:
    503
    Tony Meyer
    Jul 6, 2004
  3. Andrew McNamara

    Re: big letter -> small letter

    Andrew McNamara, Jul 6, 2004, in forum: Python
    Replies:
    2
    Views:
    749
    Scott David Daniels
    Jul 6, 2004
  4. shailesh
    Replies:
    1
    Views:
    780
    Tim Golden
    Mar 28, 2007
  5. lar
    Replies:
    0
    Views:
    195
Loading...

Share This Page