def reject(filename, filter):
    """ Takes a filename and a filter to reject files that match."""
if len(filter) == 0:
    return False
else:
    return fnmatch.fnmach(filename, filter[0]) or reject(filename, filter[1:])
matches.extend([os.path.join(root, fn) for fn in filenames if not reject(fn,
    ignore_files)])
Python, how to implement something like .gitignore behavior