fnmatch and recursive path match with `**`

admin

Administrator
Staff member
Is there any built-in or straightforward way to match paths recursively with double asterisk, e.g. like <a href="http://lorenzod8n.wordpress.com/2007/05/10/recursive-globbing-in-zsh/" rel="nofollow">zsh</a> does?

For example, with

Code:
path = 'foo/bar/ham/spam/eggs.py'

I can use <a href="http://docs.python.org/2/library/fnmatch.html#fnmatch.fnmatch" rel="nofollow">fnmatch</a> to test it with

Code:
fnmatch(path, 'foo/bar/ham/*/*.py'

Although, I would like to be able to do:

Code:
fnmatch(path, 'foo/**/*.py')

I know that fnmatch <a href="https://github.com/python-git/python/blob/master/Lib/fnmatch.py" rel="nofollow">maps its pattern to regex</a>, so in the words case I can roll my own fnmatch with additional
Code:
**
pattern, but maybe there is an easier way