Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Determine if windows drive letter is hard drive or optical from python?

Reply
Thread Tools

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

 
 
mh
Guest
Posts: n/a
 
      05-27-2005
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

 
Reply With Quote
 
 
 
 
Do Re Mi chel La Si Do
Guest
Posts: n/a
 
      05-27-2005
Hi !

You can use WMI, for that.

Michel Claveau



 
Reply With Quote
 
 
 
 
Wolfgang Strobl
Guest
Posts: n/a
 
      05-28-2005
"mh" <(E-Mail Removed)>:

>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
 
Reply With Quote
 
Magnus Lycka
Guest
Posts: n/a
 
      05-30-2005
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...
 
Reply With Quote
 
Wolfgang Strobl
Guest
Posts: n/a
 
      05-31-2005
Magnus Lycka <(E-Mail Removed)>:

>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: big letter -> small letter Andrew McNamara Python 2 07-06-2004 02:09 PM
big letter -> small letter vertigo Python 4 07-06-2004 07:23 AM
RE: big letter -> small letter Tony Meyer Python 0 07-06-2004 07:11 AM



Advertisments