os.walk(entire filesystem)

Peter Hansen peter at engcorp.com
Wed Mar 9 18:44:40 EST 2005


rbt wrote:
> More of an OS question than a Python question, but it is Python related 
> so here goes:
> 
> When I do os.walk('/') on a Linux computer, the entire file system is 
> walked. On windows, however, I can only walk one drive at a time (C:\, 
> D:\, etc.). Is there a way to make os.walk() behave on Windows as it 
> behaves on Linux? I'd like to walk the entire file system at once... not 
> one drive at a time.

Basically, no, I don't think so.  The two operating systems
have different concepts of what a file system is, and Linux
sees the world from one root, while Windows has many.

But that aside, is there anything stopping you from just
writing your own wrapper routine that does the right
thing** on Windows?

-Peter

** "Right thing" might be tricky: walking all drive letters
would *really* annoy me in most programs, since some of them
are network shares, some of them are removable storage like
CompactFlash modules, and some might just be "subst" drives
that map to a subfolder on another drive.  Make sure you
at least check with the appropriate Windows API which
drives are really local storage and stick to them.



More information about the Python-list mailing list