473,888 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4704
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.GetLog icalDriveString s(),check the drive type with
win32file.GetDr iveType() 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.ne t> wrote:
You would need a wrapper to retrieve all logical drives using
win32api.GetLog icalDriveString s(),check the drive type with
win32file.GetDr iveType() and then os.walk() those local fixed drives.


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

--
Cheers,
Simon B,
si***@brunningo nline.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
9374
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 structure, no? Also,it generates the below error during the os.renames section, but the odd thing is that it actually renames the files before saying it can't find them. Any ideas are welcomed. If I'm doing something *really* wrong here, just let me...
4
8083
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
2354
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 half-way there, but I can't quite figure out how to do the hierarchal sum. Here is the output I'm getting: /home/kirk/.gconf/apps/ggv/layout consumes 228 bytes in 1 non-directory files /home/kirk/.gconf/apps/ggv consumes 0 bytes in 1 non-directory...
3
2609
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 maintain or add features to. I'd like to have a function that builds a list of files with os.walk() and then have other functions accept that list as a parameter and modify it as needed. For example, if the user has specified that certain files...
7
1721
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 the function). It's odd, when the program goes into that statment... even when only a 'pass', and nothing else is present, nothing is returned. Why is that? I'm testing Python 2.4 on Linux x86 and WinXP. Results are the same on either...
8
3803
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 doing multiple os.stat() on dirs and files from different methods.
7
3659
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
5423
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 previousSibling could be a node which has childNodes and therefore the 'true' previousSibling would be the *deepest* lastChild of the previousSibling... For example, given this graph: 1 myAnchor nodeType 1 2 myAnchorText1 nodeType 3
0
9961
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11182
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.