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
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
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
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/
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
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.
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
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()
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
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
-- 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
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
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
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
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()
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
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
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
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
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
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
"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
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
##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
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
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
"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'
"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
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
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
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
[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
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
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
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
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
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
[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
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
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
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
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
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
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
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()?
> >
>
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
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
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
"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
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
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
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
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
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
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
"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:
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
[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
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\
[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
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
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
201 - 262 of 262 matches
Mail list logo