Suppose we have two file paths
C:\User\JohnDoe\Desktop\Happy\Happy\Expression\Smile.exe
C:\User\JohnDoe\Desktop\Happy\Expression\Smile.exe
We need to extract file path after the last mention of Happy.
Desired string should be
..\Expression\Smile.exe
for both cases.
How do we achieve this using python?
I thought of using split function
a = 'C:\\User\\JohnDoe\\Desktop\\Happy\\Happy\\Expression\\Smile.exe'
b = 'C:\\User\\JohnDoe\\Desktop\\Happy\\Expression\\Smile.exe'
print( a.split("Happy"))
print('..'+b.split("Happy")[1])
Output
['C:\\User\\JohnDoe\\Desktop\\', '\\', '\\Expression\\Smile.exe']
..\Expression\Smile.exe
I know that the first print statement is incorrect. Is there any cleaner way of doing this?