Enumerating drives in Python or wxPython
Alan Miller
ajm at enteract.com
Fri Jul 14 18:46:21 EDT 2000
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.
My biggest concern was that it might not report a removable drive if it
didn't have media in it, but I didn't have problems with either the
floppy or IDE Zip drives in my system. It did take a moment while it
checked the empty drives, but I don't know that there's any way around
that since Explorer does the same.
It seems that isdir() doesn't die if there's no media, but I can only
assume that the implementation is buried in the code for python itself
(os.path.isdir is really ntpath.isdir, which calls os.stat, which is
really nt.stat, and nt is one of the builtins) which I haven't
downloaded. Note that the root directory does seem to be handled as a
special case, since it's always going to exist on any drive under
DOS/Windows.
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.
ajm
More information about the Python-list
mailing list