Posted By: Joan Venge
How to get the filename without the extension from a path in Python?
For instance, if I had
"/path/to/some/file.txt", I would want
Getting the name of the file without the extension:
import os print(os.path.splitext("/path/to/some/file.txt"))
Important Note: If the filename has multiple dots, only the extension after the last one is removed. For example:
import os print(os.path.splitext("/path/to/some/file.txt.zip.asc"))
See other answers below if you need to handle that case.