def find_files(regex, topdir=curdir, exclude=None, exclude_vcs=True, exclude_datalad=False, dirs=False):
    'Generator to find files matching regex\n\n    Parameters\n    ----------\n    regex: basestring\n    exclude: basestring, optional\n      Matches to exclude\n    exclude_vcs:\n      If True, excludes commonly known VCS subdirectories.  If string, used\n      as regex to exclude those files (regex: `%r`)\n    exclude_datalad:\n      If True, excludes files known to be datalad meta-data files (e.g. under\n      .datalad/ subdirectory) (regex: `%r`)\n    topdir: basestring, optional\n      Directory where to search\n    dirs: bool, optional\n      Whether to match directories as well as files\n    '
    for (dirpath, dirnames, filenames) in os.walk(topdir):
        names = ((dirnames + filenames) if dirs else filenames)
        paths = (op.join(dirpath, name) for name in names)
        for path in filter(re.compile(regex).search, paths):
            path = path.rstrip(sep)
            if (exclude and re.search(exclude, path)):
                continue
            if (exclude_vcs and re.search(_VCS_REGEX, path)):
                continue
            if (exclude_datalad and re.search(_DATALAD_REGEX, path)):
                continue
            (yield path)
Generator to find files matching regex

Parameters
----------
regex: basestring
exclude: basestring, optional
  Matches to exclude
exclude_vcs:
  If True, excludes commonly known VCS subdirectories.  If string, used
  as regex to exclude those files (regex: `%r`)
exclude_datalad:
  If True, excludes files known to be datalad meta-data files (e.g. under
  .datalad/ subdirectory) (regex: `%r`)
topdir: basestring, optional
  Directory where to search
dirs: bool, optional
  Whether to match directories as well as files
def find_files(regex, topdir=curdir, exclude=None, exclude_vcs=True, exclude_datalad=False, dirs=False):
    'Generator to find files matching regex\n\n    Parameters\n    ----------\n    regex: basestring\n    exclude: basestring, optional\n      Matches to exclude\n    exclude_vcs:\n      If True, excludes commonly known VCS subdirectories.  If string, used\n      as regex to exclude those files (regex: `%r`)\n    exclude_datalad:\n      If True, excludes files known to be datalad meta-data files (e.g. under\n      .datalad/ subdirectory) (regex: `%r`)\n    topdir: basestring, optional\n      Directory where to search\n    dirs: bool, optional\n      Whether to match directories as well as files\n    '
    for (dirpath, dirnames, filenames) in os.walk(topdir):
        names = ((dirnames + filenames) if dirs else filenames)
        paths = (op.join(dirpath, name) for name in names)
        for path in filter(re.compile(regex).search, paths):
            path = path.rstrip(sep)
            if (exclude and re.search(exclude, path)):
                continue
            if (exclude_vcs and re.search(_VCS_REGEX, path)):
                continue
            if (exclude_datalad and re.search(_DATALAD_REGEX, path)):
                continue
            (yield path)