Utility functions

This module contains utility functions to work with file names and extensions.

alpaca.utils.get_file_name(source, output_dir=None, extension=None, suffix=None)[source]

Function that generates a file name with extension extension and the same base name as in source. The full path is based on output_dir if specified. Otherwise, it will be the same path as source. User and relative paths are expanded.

Parameters:
sourcestr or Path-like

Source path or file name to generate the new file name. The base name will be considered.

output_dirstr, optional

If not None, the generated file name will have this path. Default: None

extensionstr, optional

If not None, the extension of the generated file name will be changed to extension. If None, the same extension as source will be used. The extension may start with period. Default: None

suffixstr, optional

If not None, this will be added as a suffix to the base name of source, before the extension. Default: None

Returns:
str

File name, according to the parameters selected. If both output_dir and extension are None, the result will be equal to source. The result path is absolute, with user and relative paths expanded.