Reputation: 205
I have a string looks like this
urse/project/kb/use.js
from this string i need to get
urse/project/kb/
use.js
the name will always change except .js
.
Or delete the string till the first /
from the end?
Upvotes: 0
Views: 120
Reputation: 500773
Python has a dedicated module for dealing with file paths:
In [13]: os.path.dirname('urse/project/kb/use.js')
Out[13]: 'urse/project/kb'
Append a trailing os.sep
as required (or, better yet, stick to using the os.path
module for manipulating paths).
Upvotes: 7
Reputation: 4976
>>> s = 'urse/project/kb/use.js'
>>> s[:s.rfind('/') + 1]
'urse/project/kb/'
Upvotes: 2