473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

os.walk(entire filesystem)

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
6 4641
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: hokieghal99 | last post by:
This script is not recursive... in order to make it recursive, I have to call it several times (my kludge... hey, it works). I thought os.walk's sole purpose was to recursively walk a directory...
4
by: Florian Lindner | last post by:
Hello, when I'm walking through a file system hierarchy using os.walk, how can I get the full path of a file or dir? normpath and abspath don't work. Thx, Florian
5
by: Kirk Job-Sluder | last post by:
Hrm, I'm a bit stumped on this. I want to write a script lists a file directory hierarchy and gives me a sorted list showing cumulative directory size. The example code for os.walk gets me...
3
by: rbt | last post by:
I'm trying to write very small, modular code as functions to break up a big monolithic script that does a file system search for particular strings. The script works well, but it's not easy to...
7
by: rbt | last post by:
This function is intended to remove unwanted files and dirs from os.walk(). It will return correctly *IF* I leave the 'for fs in fs_objects' statement out (basically leave out the entire purpose of...
8
by: fuzzylollipop | last post by:
I am trying to get the number of bytes used by files in a directory. I am using a large directory ( lots of stuff checked out of multiple large cvs repositories ) and there is lots of wasted time...
7
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
22
by: delraydog | last post by:
It's quite simple to walk to the DOM tree going forward however I can't figure out a nice clean way to walk the DOM tree in reverse. Checking previousSibling is not sufficient as the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.