I have a path as a string in python:
path = "/folder_a/folder_b/folder_c/folder_d"
How can I extract the name of the last folder ("folder_d") from the path?
You can use os.path.basename:
>>> path = "/folder_a/folder_b/folder_c/folder_d"
>>> import os
>>> os.path.basename(path)
'folder_d'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With