file system iteration

Gerrit Holl gerrit at nl.linux.org
Mon Oct 9 08:52:46 EDT 2006


On 2006-10-09 14:45:35 +0200, rick wrote:
> import os.path
> 
> paths = []
> 
> if os.path.isdir('A:/'):
>     paths.append('A:/')
> 
> if os.path.isdir('B:/'):
>     paths.append('B:/')
> 
> ...
> 
> That's a kludge, but it works OK. I'm sure WMI may have a function that 
> returns mounted volumes, but under the circumstances currently, I can 
> only use the standard Python library. Any ideas on how to do this better?

The very least you can try:

import string
string.ascii_uppercase

for c in string.ascii_uppercase:
    if os.path.isdir('%s:/' % c):
        ...

etc.
But I suppose there should be a better way.

Gerrit.



More information about the Python-list mailing list