By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,838 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,838 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
Hi !

You can use WMI, for that.

Michel Claveau

Jul 19 '05 #2

P: n/a
"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

P: n/a
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

P: n/a
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.