How can i access logical drives in Python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenz9822
    New Member
    • Feb 2010
    • 1

    #1

    How can i access logical drives in Python?

    HI all,

    In the Python script i'm developing I need to get the names of the Drives(C:,D:,.. etc) in the OS. The script should run on 32 as well as 64 bit OS.

    Thanks in advance :-)
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I don't know of a direct way to get a list of the drives, but you can use the os module to test for valid paths. Example:
    Code:
    >>> import os
    >>> for d in (list("abcdefghijklmn")):
    ... 	if os.path.exists("%s:\\" % (d)):
    ... 		print "Drive letter '%s' is in use." % (d)
    ... 	else:
    ... 		print "Drive letter '%s' is not in use." % (d)
    ... 		
    Drive letter 'a' is in use.
    Drive letter 'b' is not in use.
    Drive letter 'c' is in use.
    ..............

    Comment

    Working...