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

M

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
 
W

Wolfgang Strobl

mh said:
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..... driveletters=[]
.... for drive in string.letters[len(string.letters)/2:]:
.... if win32file.GetDriveType(drive+":")==win32file.DRIVE_FIXED:
.... driveletters.append(drive+":")
.... return driveletters
....['C:', 'F:']
 
M

Magnus Lycka

Wolfgang said:
... 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...
 
W

Wolfgang Strobl

Magnus Lycka said:
Wolfgang said:
... 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 ...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top