get_ext#
- get_ext(file_path: str | CloudPath | Path, curate_dir_extensions=True, start_with_point: bool = True) str[source]#
Get file extension from file path.
Warning
Extension is given WITHOUT THE FIRST POINT if
start_with_pointis set to FalseHandle chained extensions with
gzonly.Therefore zipped directory extensions such as
SAFEorSEN3will be ignored (.SAFE.zipwill return.zip). This is wanted.Only accept
SAFE,SEN3,datain existing directory extensions ifcurate_dir_extensionsis True
- Parameters:
file_path (AnyPathStrType) – Absolute or relative file path (the file doesn’t need to exist)
curate_dir_extensions (bool) – If True, only accept
SAFE,SEN3,datain existing directory extensionsstart_with_point (bool) – Extensions starts with a point to follow pathlib’s logic. Set it to False to get back to older behaviour
- Returns:
File or directory extension
- Return type:
Examples
>>> path = = 'D:/path/to/filename.zip' >>> get_ext(path) '.zip'
>>> path = = 'D:/path/to/filename.zip' >>> get_ext(path, start_with_point=False) 'zip'
>>> path = = 'D:/path/to/filename.tar.gz' >>> get_ext(path) '.tar.gz'
>>> path = = 'D:/S1A_IW_GRDH_1SDV_20260523T071052_20260523T071117_064641_082495_04CE.SAFE.zip' >>> get_ext(path) '.zip'
>>> path = 'D:/S1A_IW_GRDH_1SDV_20260523T071052_20260523T071117_064641_082495_04CE.SAFE' >>> get_ext(path) '.SAFE'
>>> path = 'D:/HLS.L30.T42RVR.2022240T055634.v2.0' # Has to truly exist >>> get_ext(path) ''
>>> path = 'D:/HLS.L30.T42RVR.2022240T055634.v2.0' >>> get_ext(path, curate_dir_extensions=False) '.0'
>>> path = 'D:/HLS.L30.T42RVR.2022240T055634.v2.0.B01.tif' # Has to truly exist >>> get_ext(path) '.tif'