
Paul Moore <p.f.moore@...> writes:
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.
Agreed. This was in packaging/distutils2 and I have now got it in distlib [1]; it supports both recursive globs and variants using the {opt1,opt2,op3} syntax.
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.
Isn't the requirement to recurse implied by the presence of '**' in the pattern? What's to be gained by specifying it using allow_recursive as well? Will having allow_recursive=True have any effect if '**' is not in the pattern? If you specify a pattern with '**' and allow_recursive=False, does that mean that '**' effectively acts as '*' would (i.e. one directory level only)? Regards, Vinay Sajip [1] https://bitbucket.org/vinay.sajip/distlib/src/29666/distlib/glob.py?at=defau...