Python Program - Get the File Name From the File Path

here's a Python program that gets the file name from a file path:

import os

filepath = input("Enter the file path: ")

# get the file name from the file path
filename = os.path.basename(filepath)

print("File name:", filename)
Source:w‮gi.ww‬iftidea.com

In this program, we first use the input() function to get the file path from the user, and store it in the variable filepath.

We then use the os.path.basename() function to extract the file name from the file path, and store it in the variable filename.

Finally, we print out the file name using the print() function.