Re: Faster os.walk()

2005-04-20 Thread fuzzylollipop
du is faster than my code that does the same thing in python, it is highly optomized at the os level. that said, I profiled spawning an external process to call du and over the large number of times I need to do this it is actually slower to execute du externally than my os.walk() implementation

Re: Faster os.walk()

2005-04-20 Thread Peter Hansen
Laszlo Zsolt Nagy wrote: fuzzylollipop wrote: 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

Re: Faster os.walk()

2005-04-20 Thread Laszlo Zsolt Nagy
fuzzylollipop wrote: 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. Do you need

Faster os.walk()

2005-04-20 Thread fuzzylollipop
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. -- http://mail.python.org/mailman/

Re: newbie : prune os.walk

2005-03-11 Thread Tim Roberts
Rory Campbell-Lange <[EMAIL PROTECTED]> wrote: > >Hi. How can I list root and only one level down? I've tried setting dirs >= [] if root != start root, but it doesn't work. I clearly don't >understand how the function works. I'd be grateful for some pointers. The statement dir = [] does not ac

Re: os.walk(entire filesystem)

2005-03-11 Thread Simon Brunning
On Thu, 10 Mar 2005 20:11:10 +0100, Uwe Becher <[EMAIL PROTECTED]> 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.

Re: newbie : prune os.walk

2005-03-10 Thread Scott David Daniels
Rory Campbell-Lange wrote: Hi. How can I list root and only one level down? I've tried setting dirs = [] if root != start root, but it doesn't work. I clearly don't understand how the function works. I'd be grateful for some pointers. base = '/tmp/test' fo

Re: os.walk(entire filesystem)

2005-03-10 Thread Uwe Becher
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()

Re: newbie : prune os.walk

2005-03-10 Thread Peter Hansen
Rory Campbell-Lange wrote: Hi. How can I list root and only one level down? I've tried setting dirs = [] if root != start root, but it doesn't work. It sounds like you are trying to take advantage of the feature described in the docs where "the caller can modify the dirnames list in-place (perhaps

Re: newbie : prune os.walk

2005-03-10 Thread Diez B. Roggisch
Untestet: def foo(base, depth=2): for root, dirs, files in os.walk(base, True): if len(root.split(os.sep)) < depth: yield root, dirs, files for root, dirs, files in foo("/tmp"): print root, dirs, files -- Regards, Diez B. Roggisch -- http://ma

newbie : prune os.walk

2005-03-10 Thread Rory Campbell-Lange
-- one | |-- 1 | |-- 2 | |-- 3 | |-- 4 | `-- subone <- dont want to see this `-- two |-- 5 |-- 6 |-- 7 `-- 8 3 directories, 12 files >>> for root, dirs, files in os.walk('/tmp/test', True): ... print roo

Re: os.walk(entire filesystem)

2005-03-09 Thread Grumman
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 abilit

Re: os.walk(entire filesystem)

2005-03-09 Thread Larry Bates
d 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

Re: os.walk(entire filesystem)

2005-03-09 Thread 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 dr

Re: os.walk(entire filesystem)

2005-03-09 Thread Peter Hansen
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()

os.walk(entire filesystem)

2005-03-09 Thread 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

Re: exclude binary files from os.walk

2005-02-25 Thread Bengt Richter
On Wed, 26 Jan 2005 18:25:09 -0500, "Dan Perl" <[EMAIL PROTECTED]> wrote: > >"rbt" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> Is there an easy way to exclude binary files (I'm working on Windows XP) >> from the file

Re: os.walk()

2005-02-17 Thread Mike Meyer
rbt <[EMAIL PROTECTED]> writes: > Could someone demonstrate the correct/proper way to use os.walk() to > skip certain files and folders while walking a specified path? I've > read the module docs and googled to no avail and posted here about > other os.walk issues, but I

Re: os.walk()

2005-02-17 Thread Max Erickson
os.walk() is a generator. When you iterate over it, like in a for loop, as for r,ds,fs in os.walk(...): r, ds and fs are set to new values at the beginning of each iteration. If you want to end up with a list of files or dirs, rather than processing them in the bodies of the file and dir for

Re: os.walk()

2005-02-17 Thread rbt
Roel Schroeven wrote: rbt wrote: The problem I run into is that some of the files and dirs are not removed while others are. I can be more specific and give exact examples if needed. On WinXP, 'pagefile.sys' is always removed, while 'UsrClass.dat' is *never* removed, etc. Keep in mind that the com

Re: os.walk()

2005-02-17 Thread Roel Schroeven
rbt wrote: > The problem I run into is that some of the files and dirs are not > removed while others are. I can be more specific and give exact examples > if needed. On WinXP, 'pagefile.sys' is always removed, while > 'UsrClass.dat' is *never* removed, etc. Keep in mind that the comparisons are d

Re: os.walk()

2005-02-17 Thread Dan Perl
"rbt" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Could someone demonstrate the correct/proper way to use os.walk() to skip > certain files and folders while walking a specified path? I've read the > module docs and googled to no avail and p

os.walk()

2005-02-17 Thread rbt
Could someone demonstrate the correct/proper way to use os.walk() to skip certain files and folders while walking a specified path? I've read the module docs and googled to no avail and posted here about other os.walk issues, but I think I need to back up to the basics or find another to

Re: more os.walk() issues... probably user error

2005-02-16 Thread Kent Johnson
##fs[1].remove(d) Will the changes I made (file and dir removals from os.walk()) be reflected in the generator object? Is it safe to remove objects this way and pass the results in a generator on to another function? Sorry for all the questions, I just like to fully understand something

Re: more os.walk() issues... probably user error

2005-02-16 Thread rbt
Kent Johnson wrote: rbt wrote: rbt wrote: 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 pr

Re: more os.walk() issues... probably user error

2005-02-16 Thread Kent Johnson
rbt wrote: rbt wrote: 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 s

Re: more os.walk() issues... probably user error

2005-02-16 Thread Dan Perl
"rbt" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > def build_clean_list(self, path): > > file_skip_list = ['search_results.txt'] > dir_skip_list = ['dev', 'proc', 'Temporary Internet Files'

Re: more os.walk() issues... probably user error

2005-02-16 Thread Dan Perl
"rbt" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > rbt wrote: >> 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

Re: more os.walk() issues... probably user error

2005-02-16 Thread [EMAIL PROTECTED]
That's an easy one: fs_objects is not modified by your ode, so you get it back as created by os.walk -- http://mail.python.org/mailman/listinfo/python-list

Re: more os.walk() issues... probably user error

2005-02-16 Thread rbt
rbt wrote: 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... e

more os.walk() issues... probably user error

2005-02-16 Thread rbt
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 whe

Re: os.walk() usage

2005-02-15 Thread rbt
[EMAIL PROTECTED] wrote: every object in os.walk() returns a 3-tuple, like below, it seems your code assumes it returns only a list of files. for d in os.walk('c:\\temp'): (dirpath, dirnames, filenames) = d print dirpath print dirnames print filenames

RE: os.walk() usage

2005-02-15 Thread Batista, Facundo
Title: RE: os.walk() usage [rbt] #- The problem I'm encountering is passing the list to other functions. #- It's almost as if each function needs to build the list #- itself (walk the #- filesystem)... which gets in the way of what I was asked to #- do (break #- this thi

Re: os.walk() usage

2005-02-15 Thread bruno modulix
t 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 and folders be excluded from the walk, I'd like to have functions like this: def build_list(path): fs_list = os.w

Re: os.walk() usage

2005-02-15 Thread [EMAIL PROTECTED]
every object in os.walk() returns a 3-tuple, like below, it seems your code assumes it returns only a list of files. for d in os.walk('c:\\temp'): (dirpath, dirnames, filenames) = d print dirpath print dirnames print filenames -- http://mail.python.o

os.walk() usage

2005-02-15 Thread rbt
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 fil

Re: Hack with os.walk()

2005-02-12 Thread Michael Spencer
les = [] # list of File objects self.subdirs = [] # list of sub-Directory objects class File(HasPath): pass [snip] def build_tree(path, Directory=Directory, File=File): top = Directory(path) path2dir = {path: top} for root, dirs, files in os.walk(path): dirobj = path2

Re: Hack with os.walk()

2005-02-12 Thread Tim Peters
[Frans Englich] ... > My problem, AFAICT, with using os.walk() the usual way, is that in order to > construct the /hierarchial/ XML document, I need to be aware of the directory > depth, and a recursive function handles that nicely; os.walk() simply > concentrates on figuring out

Re: Hack with os.walk()

2005-02-12 Thread Fernando Perez
Robert Kern wrote: > Fernando Perez wrote: > >> Perhaps this path.py could be considered for inclusion in the stdlib? I've >> only >> read the page linked above, so perhaps it can use some polishing. But it >> certainly looks like a big improvement over the scatterblast which the stdlib >> is o

Re: Hack with os.walk()

2005-02-12 Thread Robert Kern
Fernando Perez wrote: Perhaps this path.py could be considered for inclusion in the stdlib? I've only read the page linked above, so perhaps it can use some polishing. But it certainly looks like a big improvement over the scatterblast which the stdlib is on this particular topic. I'm pretty sure

Re: Hack with os.walk()

2005-02-12 Thread Fernando Perez
Michael Spencer wrote: > The path module by Jorendorff: http://www.jorendorff.com/articles/python/path/ > > wraps various os functions into an interface that can make this sort of thing > cleaner Wow, many thanks for the pointer. This has to be one of the single most useful small python modules

Re: Hack with os.walk()

2005-02-12 Thread Michael Spencer
Frans Englich wrote: Hello, Have a look at this recursive function: def walkDirectory( directory, element ): element = element.newChild( None, "directory", None ) # automatically appends to parent element.setProp( "name", os.path.basename(directory)) for root, di

Hack with os.walk()

2005-02-12 Thread Frans Englich
Hello, Have a look at this recursive function: def walkDirectory( directory, element ): element = element.newChild( None, "directory", None ) # automatically appends to parent element.setProp( "name", os.path.basename(directory)) for root, dirs, files i

Re: exclude binary files from os.walk

2005-01-27 Thread Alex Martelli
Craig Ringer <[EMAIL PROTECTED]> wrote: > That's not really safe when dealing with utf-8 files though, and IIRC > with UCS2 or UCS4 as well. The Unicode BOM its self might (I'm not sure) > qualify as ASCII. Nope, both bytes in the BOM have the high-order bit set -- they're 0xFF and 0xFE -- so the

Re: exclude binary files from os.walk

2005-01-27 Thread Alex Martelli
rbt <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: > > On 2005-01-26, rbt <[EMAIL PROTECTED]> wrote: > > > >>Is there an easy way to exclude binary files (I'm working on > >>Windows XP) from the file list returned by os.walk()? > > >

Re: exclude binary files from os.walk

2005-01-27 Thread Mark McEahern
The OP wrote: > Is there an easy way to exclude binary files (I'm working on Windows XP) from the file list returned by os.walk()? Sure, piece of cake: #!/usr/bin/env python import os def textfiles(path): include = ('.txt', '.csv',) for root, dirs, files in os

Re: exclude binary files from os.walk

2005-01-26 Thread Craig Ringer
On Wed, 2005-01-26 at 17:32 -0500, rbt wrote: > Grant Edwards wrote: > > On 2005-01-26, rbt <[EMAIL PROTECTED]> wrote: > > > > > >>Is there an easy way to exclude binary files (I'm working on > >>Windows XP) from the file list returned by os.walk

Re: exclude binary files from os.walk

2005-01-26 Thread Grant Edwards
On 2005-01-26, Larry Bates <[EMAIL PROTECTED]> wrote: > There's no definitive way of telling a file is "non-ascii". > Bytes in a binary file define perfectly good ascii characters. As long as bit 7 is a 0. Traditional ASCII only allows/defines the values 0x00 through 0x7f. If that's what is m

Re: exclude binary files from os.walk

2005-01-26 Thread Dan Perl
"rbt" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is there an easy way to exclude binary files (I'm working on Windows XP) > from the file list returned by os.walk()? > > Also, when reading files and you're unsure as to whether or not th

Re: exclude binary files from os.walk

2005-01-26 Thread [EMAIL PROTECTED]
you might want to look up the 'isascii' function... i.e. - can be represented using just 7-bits. -- http://mail.python.org/mailman/listinfo/python-list

Re: exclude binary files from os.walk

2005-01-26 Thread Larry Bates
indows XP) from the file list returned by os.walk()? Sure, assuming you can provide a rigorous definition of 'binary files'. :) non-ascii -- http://mail.python.org/mailman/listinfo/python-list

Re: exclude binary files from os.walk

2005-01-26 Thread rbt
Grant Edwards wrote: On 2005-01-26, rbt <[EMAIL PROTECTED]> wrote: Is there an easy way to exclude binary files (I'm working on Windows XP) from the file list returned by os.walk()? Sure, assuming you can provide a rigorous definition of 'binary files'. :) non-ascii -- h

Re: exclude binary files from os.walk

2005-01-26 Thread Grant Edwards
On 2005-01-26, rbt <[EMAIL PROTECTED]> wrote: > Is there an easy way to exclude binary files (I'm working on > Windows XP) from the file list returned by os.walk()? Sure, assuming you can provide a rigorous definition of 'binary files'. :) > Also, when reading

exclude binary files from os.walk

2005-01-26 Thread rbt
Is there an easy way to exclude binary files (I'm working on Windows XP) from the file list returned by os.walk()? Also, when reading files and you're unsure as to whether or not they are ascii or binary, I've always thought it safer to 'rb' on the read, is this cor

Re: os.walk bug?

2004-12-18 Thread Alex Martelli
Terry Reedy <[EMAIL PROTECTED]> wrote: > "Alex Martelli" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > for item in alist: > >if isnasty(item): > >alist.remove(item) > > > > changing the header to ``in alist[:]:'' or ``in list(alist):'' probably > > makes this code

Re: os.walk bug?

2004-12-18 Thread Terry Reedy
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > for item in alist: >if isnasty(item): >alist.remove(item) > > changing the header to ``in alist[:]:'' or ``in list(alist):'' probably > makes this code work, but it still can't make it GOOD... good would be:

Re: os.walk bug?

2004-12-18 Thread Alex Martelli
Adam DePrince <[EMAIL PROTECTED]> wrote: > Each iteration of os.walk returns three parameters; one of those, dirs, > is a list of directories within the current directory pointed at by > root. Yes, it does. > Am I correct to assume that you beleve that by changing the con

Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Adam DePrince] > Each iteration of os.walk returns three parameters; one of those, > dirs, is a list of directories within the current directory pointed at > by root. Right. > Am I correct to assume that you beleve that by changing the > contents of dir you will affect how os.wal

Re: os.walk bug?

2004-12-16 Thread Adam DePrince
On Thu, 2004-12-16 at 14:45, Gabriel Cosentino de Barros wrote: > Hi > > I'm new to the list. i found a bad behaviour of os.walk that i can > reproduce 100% but didn't find an answer to why it does that > > I have the folowing tree: > > t:\dir1 > t:\dir1\

Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Gabriel Cosentino de Barros] ... > for root, dirs, files in os.walk('t:\'): > # -- do stuff > print "working on", root > # -- stuff done > > print 'DEBUG: dirs =', dirs > fo

Re: os.walk bug?

2004-12-16 Thread Terry Reedy
os.walk bug?--- for d in dirs: # -- remove archive if d[:2] == '20': print "--- removing:", d dirs.remove(d) -- Please post in plain text, not html/rtf. It is easier to reply

os.walk bug?

2004-12-16 Thread Gabriel Cosentino de Barros
Title: os.walk bug? Hi I'm new to the list. i found a bad behaviour of os.walk that i can reproduce 100% but didn't find an answer to why it does that I have the folowing tree: t:\dir1 t:\dir1\2000 t:\dir1\2001 t:\dir1\content t:\dir2 t:\dir2\2000 t:\dir2\2001 t:\dir2\2002 t:\d

<    1   2   3