file system iteration
rick
ath-admin at vt.edu
Mon Oct 9 08:35:54 EDT 2006
In Unix, the file system hierarchy is like a tree that has a base or
'root' that exposes objects (files and folders) that can easily be
iterated over.
\ \ | / /
\ \ | / /
\ \|/ /
\ | /
\|/
|
|
Root
So, when I do os.chdir('/') I am at the base of the tree and can now use
something like os.walk() to work with all of the file system objects.
In Windows, the file system is disjointed and there is now real 'root'
At least none that I can see. It looks more like this:
| | | | | | |
|_|_|_|_|_|_|
A B C D E F G
How do you guys handle this when working with scripts that need to touch
all files and folders on a Windows machine? I've been looping through
A-Z like this:
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?
Thanks
More information about the Python-list
mailing list