from pathlib import Path


def get_product_name_from_path(path):
    """
    Extract S2 product name from the path.
    """
    parents = list(Path(path).parents)
    if len(parents) > 1:
        first_dir = Path(parents[len(parents) - 2])
        if first_dir.suffix == '.SAFE':
            return first_dir.stem