listing computer hard drives with python

Tim Golden mail at timgolden.me.uk
Tue May 6 04:21:32 EDT 2008


Ohad Frand wrote:
> I am looking for a way to get a list of all active logical hard drives
> of the computer (["c:","d:"..])

You can do this with WMI [*] under Windows:

<code>
import wmi

c = wmi.WMI ()
for i in c.Win32_LogicalDisk ():
 print i.Caption

</code>

If you want only fixed disks (ie exluding external drives,
USB and CD drives etc) then specify DriveType=3:

<code>
import wmi

c = wmi.WMI ()
for i in c.Win32_LogicalDisk (DriveType=3):
 print i.Caption

</code>

[*] http://timgolden.me.uk/python/wmi.html

TJG




More information about the Python-list mailing list