os.walk(entire filesystem)

R

rbt

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.

Thanks!
 
P

Peter Hansen

rbt said:
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.
 
T

Tobiah

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.).

If this is a personal utility for one computer, and if you run XP on
that computer, then you have the ability to mount secondary drives
on to the file system of your main drive. This would give you the
effect that you are enjoying on the Linux side.

I am guessing that the utility that does this is the same one
that allows you to partition drives, but I'm not sure.
 
L

Larry Bates

I don't think what you want would even work. You can't walk A:
unless a floppy is present, O/S will bark at you. You can't
walk D: (cdrom drive) unless a CDROM is present. What about
network drives??? Unlike Linux where these directories appear
to be empty if nothing is mounted Windows tries to read a
directory and errors. Just follow what Peter Hansen has
suggested and write a wrapper function that calls os.walk
repeatedly for all the actual drives in your system
that are readable at all times. It isn't all that hard.

Larry Bates
 
G

Grumman

Tobiah said:
If this is a personal utility for one computer, and if you run XP on
that computer, then you have the ability to mount secondary drives
on to the file system of your main drive. This would give you the
effect that you are enjoying on the Linux side.

I am guessing that the utility that does this is the same one
that allows you to partition drives, but I'm not sure.

Ditto for win2k. right click 'My computer'->'Manage'->'Disk Management'
The only restriction is that both the root filesystem, and the one you
want to mount within it have to be NTFS. (I may be wrong, but that
appears to be true on my system.)

Still a moot point if this is to be widely deployed to existing PCs though.
 
U

Uwe Becher

rbt said:
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.

Thanks!

You would need a wrapper to retrieve all logical drives using
win32api.GetLogicalDriveStrings(),check the drive type with
win32file.GetDriveType() and then os.walk() those local fixed drives.

Hth
Uwe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top