[New-bugs-announce] [issue12793] allow filters in os.walk
Jacek Pliszka
report at bugs.python.org
Sat Aug 20 13:52:54 CEST 2011
New submission from Jacek Pliszka <jacek.pliszka at gmail.com>:
I suggest a small change in os.walk module.
Instead of:
def walk(top, topdown=True, onerror=None, followlinks=False):
I would like to have:
def walk(top, topdown=True, onerror=None, skipnames=lambda x : False, skipdirs=islink):
Implementation might be as follows:
< if isdir(join(top, name)):
---
> fullname=join(top, name)
> if skipnames(fullname):
> continue
> if isdir(fullname):
and:
< if followlinks or not islink(new_path):
< for x in walk(new_path, topdown, onerror, followlinks):
---
> if not skipdirs(new_path):
> for x in walk(new_path, topdown, onerror, skipnames, skipdirs):
This is a small change, breaks a bit 'followlinks' option but gives
much more flexibility as skipnames and skidirs can be any
functions (including ones using regexp and similar).
----------
components: Library (Lib)
files: os.diff
keywords: patch
messages: 142523
nosy: Jacek.Pliszka
priority: normal
severity: normal
status: open
title: allow filters in os.walk
type: feature request
versions: Python 3.2
Added file: http://bugs.python.org/file22960/os.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12793>
_______________________________________
More information about the New-bugs-announce
mailing list