file system iteration

Georg Brandl g.brandl-nospam at gmx.net
Mon Oct 9 15:45:08 CEST 2006


rick wrote:
> 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:

Which application needs to walk over ALL files? Normally, you just have a
starting path and walk over everything under it.

In Unix, things aren't so clear either. For example, there are symbolic links
that make the tree more complicated. Or different file system mounted on
different mount points, perhaps not even representing real files like the
/proc filesystem. All that needs caution when iterating over "all files".

Georg



More information about the Python-list mailing list