Skip to content

Io

get_files(datasets_spec, ext='.nc')

Get a list of filenames based on the provided datasets specification.

Parameters:

Name Type Description Default
datasets_spec DictConfig

The datasets specification containing the path and extension.

required
ext str

The file extension to filter the search. Defaults to ".nc".

'.nc'

Returns:

Type Description

List[str]: A list of filenames.

Source code in rs_tools/_src/utils/io.py
def get_files(datasets_spec: DictConfig, ext=".nc"):
    """
    Get a list of filenames based on the provided datasets specification.

    Args:
        datasets_spec (DictConfig): The datasets specification containing the path and extension.
        ext (str, optional): The file extension to filter the search. Defaults to ".nc".

    Returns:
        List[str]: A list of filenames.

    """
    data_path = datasets_spec.data_path
    return get_list_filenames(data_path=data_path, ext=ext)

get_list_filenames(data_path='./', ext='*')

Loads a list of file names within a directory.

Parameters:

Name Type Description Default
data_path str

The directory path to search for files. Defaults to "./".

'./'
ext str

The file extension to filter the search. Defaults to "*".

'*'

Returns:

Type Description

List[str]: A sorted list of file names matching the given extension within the directory.

Source code in rs_tools/_src/utils/io.py
def get_list_filenames(data_path: str="./", ext: str="*"):
    """
    Loads a list of file names within a directory.

    Args:
        data_path (str, optional): The directory path to search for files. Defaults to "./".
        ext (str, optional): The file extension to filter the search. Defaults to "*".

    Returns:
        List[str]: A sorted list of file names matching the given extension within the directory.
    """
    pattern = f"*{ext}"
    return sorted(glob.glob(os.path.join(data_path, "**", pattern), recursive=True))