[Python-ideas] Adding '**' recursive search to glob.glob
Paul Moore
p.f.moore at gmail.com
Mon Jan 14 14:22:27 CET 2013
This may be simple enough to just be a feature request on the tracker,
but I thought I'd post it here first to see if people thought it was a
good idea.
I'd like it if the glob module supported the (relatively common)
facility to use ** to mean recursively search subdirectories. It's a
reasonably straightforward patch, and offers a feature that is fairly
difficult to implement in user code on top of the existing
functionality. The syntax is supported in a number of places (for
example the bash shell and things like Java Ant) so it will be
relatively familiar to users.
For people who don't know the syntax, "a/**/b" is equivalent to "a/*/b
or a/*/*/b or a/*/*/*/b or ..." (for as many levels as needed).
One obvious downside is that if used carelessly, it can make globbing
pretty slow. So I'd propose that it be added as an optional extension
enabled using a flag argument (glob(pat, allow_recursive=True)) which
is false by default. That would also mean that backward compatibility
should not be an issue.
Any comments? Is this worth submitting a patch to the tracker?
Paul.
More information about the Python-ideas
mailing list