How to removes all extensions from a filename in Python

1 Answer

0 votes
from pathlib import Path


def remove_all_extensions(file_path: str) -> str:
    """
    Remove all file extensions from a filename.
    """
    path = Path(file_path)

    while path.suffix:
        path = path.with_suffix("")

    return str(path)


# Example usage
print(remove_all_extensions("archive.tar.gz"))


'''
run:

archive

'''

 



answered Oct 12 by avibootz
...