Question: I have a lot of strings like this 

```
/home/build_targets/JavaFiles/Commonfeature/CM/src/com/ems/ClusterGroupTreePanel.java

```

I need to get the file name ClusterGroupTreePanel.java out.

Is there an efficient way to achieve this in **Python**?

Answer: 
os.path.[basename](http://docs.python.org/2/library/os.path.html#os.path.basename)(path) will give you the file name, if you want to leave it out you can use [os.path.split](http://docs.python.org/2/library/os.path.html#os.path.split) and take the first part

```
os.path.split(full_path)[0]

```
This way:

```
 >>> str = '/home/build_targets/JavaFiles/Commonfeature/CM/src/com/ems/ClusterGroupTreePanel.java'
 >>> s = str.rfind('/')     
 >>> name = str[s:]

```