Get the File Name
Get the File Name From the File Path
In this example, you will learn to get the file name from the file path.
To understand this example, you should have the knowledge of the following Python programming topics:
Example 1: Using os module
Output
basename()
gives the name of the last file/folder of the path, whereas splitext()
splits the file name into filename and extension.
Output
Example 2: Using Path module
Output
It works for python 3.4 and above.
Last updated