Newbie: List file system roots

kyosohma at gmail.com kyosohma at gmail.com
Thu Aug 23 16:09:52 EDT 2007


On Aug 23, 2:48 pm, "Einar W. Høst" <eina... at notreal.com> wrote:
> Hi,
>
> How would you list the file system roots in Python? That is, I'm looking
> for a way to list all connected drives (C:, D: etc) on a Windows box, or
> all /root, /tmp etc on a *nix box. In Java, there's a built-in API
> function to do this, File.listRoots(), but I couldn't find any
> equivalents in the Python libraries.
>
> Kind regards,
> Einar

Looks like the win32 modules save the day again.

http://mail.python.org/pipermail/python-win32/2004-January/001562.html

from win32com.client import Dispatch
fso = Dispatch('scripting.filesystemobject')
for i in fso.Drives :
    print i

# Mike




More information about the Python-list mailing list