get_filename#
- get_filename(file_path: str | CloudPath | Path, other_exts: list | str = None) str[source]#
Get file name (without extension) from file path.
Warning
Never returns SAFE or SEN.3 extensions as part of the filename
To correctly handle ‘.’ based directory names (such as
HLS.L30.T42RVR.2022240T055634.v2.0), the folder must exist! Otherwise it’ll remove the ending.0…)
- Parameters:
file_path (AnyPathStrType) – Absolute or relative file path (the file doesn’t need to exist)
other_exts (list | str) – Other double extensions to discard
- Returns:
File name (without extension)
- Return type:
Example
>>> file_path = 'D:/path/to/filename.zip' >>> get_file_name(file_path) 'filename'
>>> file_path = 'D:/HLS.L30.T42RVR.2022240T055634.v2.0.B01.tif' >>> get_file_name(file_path) 'HLS.L30.T42RVR.2022240T055634.v2.0.B01'
>>> file_path = 'S1A_IW_GRDH_1SDV_20260523T071052_20260523T071117_064641_082495_04CE.SAFE.zip' >>> get_file_name(file_path) 'S1A_IW_GRDH_1SDV_20260523T071052_20260523T071117_064641_082495_04CE'
>>> folder_path = 'S1A_IW_GRDH_1SDV_20260523T071052_20260523T071117_064641_082495_04CE.SAFE' >>> get_file_name(folder_path) 'S1A_IW_GRDH_1SDV_20260523T071052_20260523T071117_064641_082495_04CE'
>>> file_path = 'D:/HLS.L30.T42RVR.2022240T055634.v2.0' # Must exist >>> get_file_name(file_path) 'HLS.L30.T42RVR.2022240T055634.v2.0'
>>> file_path = 'D:/HLS.L30.T42RVR.2022240T055634.v2.0' # If not existing... >>> get_file_name(file_path) 'HLS.L30.T42RVR.2022240T055634.v2'