path module
holger krekel
pyth at devel.trillke.net
Fri Jul 25 14:33:22 EDT 2003
Ian Bicking wrote:
> Jason had walkers both for all files, just non-directory files, and
> directory files. This seems useful to me, and by making it explicit I
> might just start distinguishing text from binary (which I don't now
> because I am forgetful). And a globbing walker, though I don't know how
> much of an advantage that would be over list comprehension. Actually,
> all his walkers have a globbing option.
We currently only have one 'visit' method that accepts a filter for returning
results and a filter for recursing into the tree. You can use and
combine multiple filters like so:
root = Path('...)
for path in root.visit(AND(isdir, nolink)):
# iterates over all non-link dirs in the tree (breadth-first)
or
for path in root.visit(AND(isfile, endswith('.txt')), nodotfile):
# iterates over all '*.txt' files but not recursing into ".*"
and so on. This proved to be flexible and convenient and mostly avoids
the need for multiple walk-methods.
cheers,
holger
More information about the Python-list
mailing list