473,508 Members | 2,206 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3456
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2705
by: hokieghal99 | last post by:
What are the specific steps that one should take to make a python script that works on a Linux x86 machine also work on a Windows x86 machine? I am using os, re and string in the script. How do...
12
8187
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
0
2479
by: john doe | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
7
24120
by: jimdscudder | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
6
11192
by: Charles Neitzel | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
1
3137
by: Charles | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
3
6798
by: KSC | last post by:
Hello, Is there a way to programmatically determine if a directory is shared and if so, what the sharename is? It seems a simple question, but I have been searching and not found the...
7
3581
by: BWill | last post by:
Hi, I'm writing a file browser, but I'm not sure how I could go about detecting the drives available on windows and linux systems (preferably using the standard modules if possible). I guess I...
3
10047
by: johnb41 | last post by:
I need to find out what the current drive letter that is being used for the application. Because i want to copy/move files to a fixed path, and don't want to hard code in "C:\" when it's not...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.