This MUST have been asked before, but I can't seem to Google the right
thing. *How can I get a list of drives on a Windows box, like ["C:\",
"D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
Thanks!
Bob 7 20183
On May 20, 2:18*pm, Bob Greschke <b...@passcal.nmt.eduwrote:
This MUST have been asked before, but I can't seem to Google the right
thing. *How can I get a list of drives on a Windows box, like ["C:\",
"D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
Thanks!
Bob
>>import os.path
>>dl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>drives = ['%s:' % d for d in dl if os.path.exists('%s:' % d)] drives
['C:', 'D:', 'F:', 'G:', 'H:', 'I:', 'J:', 'M:', 'N:', 'O:', 'P:',
'Q:', 'R:', 'S:', 'T:', 'U:', 'X:', 'Y:']
Bob Greschke wrote:
This MUST have been asked before, but I can't seem to Google the right
thing. How can I get a list of drives on a Windows box, like ["C:\",
"D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
A couple of options to get the ball rolling:
1) win32api.GetLogicalDriveStrings()
2) http://timgolden.me.uk/python/wmi_co...nd-drive-types
TJG
On May 20, 2:45*pm, Tim Golden <m...@timgolden.me.ukwrote:
Bob Greschke wrote:
This MUST have been asked before, but I can't seem to Google the right
thing. *How can I get a list of drives on a Windows box, like ["C:\",
"D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
A couple of options to get the ball rolling:
1) win32api.GetLogicalDriveStrings()
I gave this a go to see how it worked and ti gave me this:
'A:\\\x00C:\\\x00D:\\\x00G:\\\x00I:\\\x00L:\\\x00P :\\\x00Q:\\\x00R:\\
\x00U:\\\x00X:\\\x00Y:\\\x00Z:\\\x00'
Not exactly what I expected. Do I have to parse out the "\\\x00"
myself or is there an information level switch I should add?
>
2)http://timgolden.me.uk/python/wmi_co...nd-drive-types
This works as advertised. I was actually going to post that, but you
beat me to it. :)
>
TJG
Mike
Mensanator,
<snip>
>>import os.path dl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' drives = ['%s:' % d for d in dl if os.path.exists('%s:' % d)] drives
</snip>
Very clever!
Malcolm
Mike Driscoll schrieb:
On May 20, 2:45 pm, Tim Golden <m...@timgolden.me.ukwrote:
>Bob Greschke wrote:
>>This MUST have been asked before, but I can't seem to Google the right thing. How can I get a list of drives on a Windows box, like ["C:\", "D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
A couple of options to get the ball rolling:
1) win32api.GetLogicalDriveStrings()
I gave this a go to see how it worked and ti gave me this:
'A:\\\x00C:\\\x00D:\\\x00G:\\\x00I:\\\x00L:\\\x00P :\\\x00Q:\\\x00R:\\
\x00U:\\\x00X:\\\x00Y:\\\x00Z:\\\x00'
Not exactly what I expected. Do I have to parse out the "\\\x00"
myself or is there an information level switch I should add?
The data is separated by NUL bytes. Split it with \x00 and you'll get a
list of drives:
>>
"A:\\\x00C:\\\x00D:\\\x00G:\\\x00I:\\\x00L:\\\x00P :\\\x00Q:\\\x00R:\\\x00U:\\\x00X:\\\x00Y:\\\x00Z:\ \\x00".split("\x00")
['A:\\', 'C:\\', 'D:\\', 'G:\\', 'I:\\', 'L:\\', 'P:\\', 'Q:\\', 'R:\\',
'U:\\', 'X:\\', 'Y:\\', 'Z:\\', '']
Christian
On May 20, 3:43*pm, Christian Heimes <li...@cheimes.dewrote:
Mike Driscoll schrieb:
On May 20, 2:45 pm, Tim Golden <m...@timgolden.me.ukwrote:
Bob Greschke wrote: This MUST have been asked before, but I can't seem to Google the right thing. *How can I get a list of drives on a Windows box, like ["C:\", "D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
A couple of options to get the ball rolling:
1) win32api.GetLogicalDriveStrings()
I gave this a go to see how it worked and ti gave me this:
'A:\\\x00C:\\\x00D:\\\x00G:\\\x00I:\\\x00L:\\\x00P :\\\x00Q:\\\x00R:\\
\x00U:\\\x00X:\\\x00Y:\\\x00Z:\\\x00'
Not exactly what I expected. Do I have to parse out the "\\\x00"
myself or is there an information level switch I should add?
The data is separated by NUL bytes. Split it with \x00 and you'll get a
list of drives:
"A:\\\x00C:\\\x00D:\\\x00G:\\\x00I:\\\x00L:\\\x00P :\\\x00Q:\\\x00R:\\\x00U:\\\x00X:\\\x00Y:\\\x00Z:\ \\x00".split("\x00")
['A:\\', 'C:\\', 'D:\\', 'G:\\', 'I:\\', 'L:\\', 'P:\\', 'Q:\\', 'R:\\',
'U:\\', 'X:\\', 'Y:\\', 'Z:\\', '']
Christian
Yeah, I noticed that. I just thought that was a weird piece of info
for the call to return.
Mike
On 2008-05-20 13:18:08 -0600, Bob Greschke <bo*@passcal.nmt.edusaid:
This MUST have been asked before, but I can't seem to Google the right
thing. *How can I get a list of drives on a Windows box, like ["C:\",
"D:\"], like I can if I do something like listdir("/Volumes") on a Mac?
Thanks!
Bob
Thanks for the ideas, guys! It's off to the emacs... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Pavel Koryakin |
last post by:
Guys, does anybody knows how can I get a list of all windows which I
see on my taskbar?
Thank you.
Pavel.
|
by: lastusernameleft |
last post by:
Is there a .NET method for doing this? I haven't found anything else that
works.
Thanks
|
by: Paige W. |
last post by:
I have added a mainmenu object to my windows form and would like to
display an MRU list on it. Is there an easy way? or do I have to do
it programatically? Can anyone point me to a good tutorial....
|
by: dev |
last post by:
Hi to all,
What is the class/technique to retrieve a list of all drive letters
available on the computer?
Thanks
Dev
|
by: Muhammad Aftab Alam |
last post by:
Hi All,
I need to know how can I make a list contorl like of windows explorer. From
windows explorer view I mean when we open My Computer a list view is shown
and the headers are shown as follows...
|
by: nagamohan_p |
last post by:
I wish to remove Host Protected Area(HPA) of Hard Disk in Windows only
through API calls... I found in Linux version ie, "setmax.c" which should be
ported to windows... It shouldn't be written...
|
by: usafshah |
last post by:
hi all
i'm installing windows xp on Maxtor SATA 300 GB but setup prompts with the error of:
setup did not find any hard disk drives....
its showing in bios
I tried to download drivers for...
|
by: =?Utf-8?B?VGFueWEgU2NodWV0eg==?= |
last post by:
My cd rom and dvd rom drives stopped working. I went to troubleshooting and
it didn't help.
cd-rom drive is a OPTORITE CD-ROM cw4802
dvdrom drive is a SAMSUNG DVD-ROM sd604
It displays this...
|
by: =?Utf-8?B?VGltIEhhbHBpbiAoQlYp?= |
last post by:
I have 2 disk drives on my pc and bot are dvd-roms and neither are working.
1 says please instert a disk even thought there is one in the drive.
The second says application not found when you...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |