Sunday, July 29, 2007

Logical Drive Enumeration in IronPython

The .Net framework has a lot of useful low level functionality in it that is kept well hidden. Writing in C# or C++/CLI, the temptation is there to P/Invoke the obvious Win32 APIs rather than go burrowing into the unexpected parts of the system. And while we could compile ourselves some P/Invoke C# on the fly in IronPython, that's sufficiently inaesthetic to make it worthwhile looking for another way.

And behold--

which gives, when I run it

['C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'I:', 'J:', 'K:', 'L:', 'N:']

There is a lot of good stuff in the WMI classes, but finding the query strings is a bit of a black art...

3 comments :

Michael Foord said...

Hey Steve,

Is it ok if I post this example to the IronPython cookbook? (or you could do it...)

I uhm... already posted your WPF example (thanks). I probably should have asked first. :-)

Steve Gilham said...

[also mailed]
Perfectly OK, That's what the

"Code snippets released under the WTFPL"

in the sidebar is about.

This sort of entry is very much "writing up my lab-book" in advance of doing anything to make it pretty.

Michael Foord said...

Thanks Steve.

Posted to:
http://www.ironpython.info/index.php/Logical_Drive_Enumeration