import glob


def get_globfiles(fileglob, minfiles=1, maxfiles=1):
    """
    Get file(s) matching ``fileglob``.  If the number of matching
    files is less than minfiles or more than maxfiles then an
    exception is raised.

    :param fileglob: Input file glob
    :param minfiles: Minimum matching files (None => no minimum)
    :param maxfiles: Maximum matching files (None => no maximum)
    """
    files = glob.glob(fileglob)
    nfiles = len(files)
    if minfiles is not None and nfiles < minfiles:
        raise ValueError('At least %d file(s) required for %s but %d found' % (minfiles, fileglob, nfiles))
    if maxfiles is not None and nfiles > maxfiles:
        raise ValueError('No more than %d file(s) required for %s but %d found' % (maxfiles, fileglob, nfiles))

    return files