Enumerating drives in Python or wxPython

db3l at fitlinxx.com.bbs db3l at fitlinxx.com.bbs
Mon Jul 17 13:40:02 EDT 2000


Alan Miller <ajm at enteract.com> writes:

> David Bolen (db3l at fitlinxx.com) wrote:
> >Alan Miller <ajm at enteract.com> writes:
> >> for driveletter in string.uppercase:
> >>     if os.path.isdir(driveletter + ":\\"):
> >>         drivelist.append(driveletter)
> >
> >The only rub with this is that for things like floppies, you can get
> >errors running isdir() if there is no diskette present.
>
> Interesting, I tried it out before I posted and didn't have any problems.

Strange - it did for me for A: (I did it just before posting as well).
Perhaps it's a Windowism that depends on platform or some strange
registry setting or something.  I was on NT 4, SP4.  In any event, I
guess at the very least it means that it's behavior isn't guaranteed
to be consistent.

(...)
> Anyway, even if isdir() did return an error that should be trappable; I'd
> expect the error returned to be different for media not available than
> for no such device.

The problem was that isdir() didn't return an error - it returned 1
(which I guess is ok, given that A:\ is technically valid even without
a diskette), but the NT error while performing isdir() put up a
message box that the user would have to answer before isdir() returned
in the Python script.

--
-- David
--
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list