469,621 Members | 1,685 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

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

mh
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

Jul 19 '05 #1
4 3286
Hi !

You can use WMI, for that.

Michel Claveau

Jul 19 '05 #2
"mh" <se******@gmail.com>:
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
Jul 19 '05 #3
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...
Jul 19 '05 #4
Magnus Lycka <ly***@carmen.se>:
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
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by hokieghal99 | last post: by
6 posts views Thread by Charles Neitzel | last post: by
7 posts views Thread by BWill | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.