from pathlib import Path


def get_ncfiles(target_directory, file_pattern=None, year=None):
    """
    Retrieve list of files, based on parameters.

    Parameters
    ----------
    target_directory : str
        DESCRIPTION.
    file_pattern : TYPE, optional
        DESCRIPTION. The default is None.
    year : TYPE, optional
        DESCRIPTION. The default is None.

    Returns
    -------
    ncfiles : list
        List of strings containing absolute path to files.

    """
    if 'str' in str(type(target_directory)):
        target_directory = Path(target_directory)
    if file_pattern and year:
        ncfiles = list(target_directory.glob(f'{file_pattern}*{year}*.nc'))
    elif file_pattern and not year:
        ncfiles = list(target_directory.glob(f'*{file_pattern}*.nc'))
    elif year and not file_pattern:
        ncfiles = list(target_directory.glob(f'*{year}*.nc'))
    else:
        ncfiles = list(target_directory.glob('*.nc'))
    return ncfiles