Get the last '/' or '\\' character in Python

Posted by wowus on Stack Overflow See other posts from Stack Overflow or by wowus
Published on 2010-03-09T01:19:18Z Indexed on 2010/03/09 1:21 UTC
Read the original article Hit count: 259

Filed under:
|

If I have a string that looks like either

./A/B/c.d

OR

.\A\B\c.d

How do I get just the "./A/B/" part? The direction of the slashes can be the same as they are passed.

This problem kinda boils down to: How do I get the last of a specific character in a string?

Basically, I want the path of a file without the file part of it.

© Stack Overflow or respective owner

Related posts about python

Related posts about string-manipulation