I have searched possible ways but I am unable to mix those up yet. I have a string that is a path to the image.

```
myString= "D:/Train/16_partitions_annotated/partition1/images/AAAAA/073-1_00191.jpeg"

```

What I want to do is replace `images` with `IMAGES` and cut off the `073-1_00191.jpeg` part at the end. Thus, the new string string should be 

```
newString = "D:/Train/16_partitions_annotated/partition1/IMAGES/AAAAA/"

```

And the chopped part (`073-1_00191.jpeg`) ***will be used separately*** as the name of processed image. The function `.replace()` doesn't work here as I need to provide `path` and `filename` as separate parameters. 

The reason why I want to do is that I am accessing images through their paths and doing some stuff on them and when saving them I need to create another directory (in this case `IMAGES`) and the next directories after that (in this case `AAAAA`) should remain the same ( together with the name of corresponding image). 

***Note that images may have different names and extensions***

*If something is not clear by my side please ask, I will try to clear up*