replace_file_extension()¶
- audeer.replace_file_extension(path, new_extension, *, ext=None)[source]¶
Replace file extension.
If
ext
isNone
it usesaudeer.file_extension()
to identify the current extension and replaces it withnew_extension
.If
ext
is notNone
butpath
ends on a different extension, the original path is returned.- Parameters
- Return type
- Returns
path to file with a possibly new extension
Examples
>>> replace_file_extension("file.txt", "rst") 'file.rst' >>> replace_file_extension("file", "rst") 'file.rst' >>> replace_file_extension("file.txt", "") 'file' >>> replace_file_extension("file.tar.gz", "zip", ext="tar.gz") 'file.zip' >>> replace_file_extension("file.zip", "rst", ext="txt") 'file.zip'