Reputation: 15
Let's say I have a = "C:\folder1\folder2\picture.jpg"
How can I assign variable b to file's name with its extension: b = 'picture.jpg'
Upvotes: 1
Views: 69
Reputation: 159
Without too many complications, you can just use the os
module as follows:
import os
a = "C:\folder1\folder2\picture.jpg"
b = os.path.basename(a)
Which will output what you desire: 'picture.jpg'
Upvotes: 1