How to get names in string?
<p>Get last name of the directory:</p>

<pre><code>str = "/folderA/folderB/folderC/folderD"
editstr = str.split("/")[-1]
print(editstr)

folderD
</code></pre>

<p>How do I get all the directories before <code>folderD</code> (without the last slash)? E.g:</p>

<pre><code>editstr = ???
print(editstr)

/folderA/folderB/folderC
</code></pre>