Newbie: List file system roots

  • Thread starter =?ISO-8859-1?Q?=22Einar_W=2E_H=F8st=22?=
  • Start date
?

=?ISO-8859-1?Q?=22Einar_W=2E_H=F8st=22?=

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
 
K

kyosohma

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
 
T

Tim Golden

Einar said:
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.

Couple of options for Windows (probably more as well):

http://timgolden.me.uk/python/win32_how_do_i/find-drive-types.html
http://timgolden.me.uk/python/wmi_cookbook.html#find-drive-types

TJG
 
B

Bjoern Schliessmann

Einar W. Høst said:
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.

/root and /tmp are no "roots", but normal directories.
glob.glob("/*") will give you all of those.

Regards,


Björn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top