By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,713 Members | 764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,713 IT Pros & Developers. It's quick & easy.

os.walk(entire filesystem)

P: n/a
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!
Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.
Jul 18 '05 #2

P: n/a
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.
Jul 18 '05 #3

P: n/a
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
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.

Thanks!

Jul 18 '05 #4

P: n/a
Tobiah wrote:
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.


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.
Jul 18 '05 #5

P: n/a
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.

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
Jul 18 '05 #6

P: n/a
On Thu, 10 Mar 2005 20:11:10 +0100, Uwe Becher <ub*****@gmx.net> wrote:
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.


http://groups-beta.google.com/group/...fc77779210007a

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.