string = "C:\\folder\\important\\week1.xlsx"
I need to extract the file name alone, "week1.xlsx" from this string. But for some reason, it doesn't work.
string = "C:\\folder\\important\\week1.xlsx"
I need to extract the file name alone, "week1.xlsx" from this string. But for some reason, it doesn't work.
You can use basename
:
import os
str(os.path.basename("C:\\folder\\important\\week1.xlsx"))
=> 'week1.xlsx'