Question: How can I strip the directory and filename out from a full path given to me as a string?

For example, from:

```
>>path_string
C:/Data/Python/Project/Test/file.txt

```

I want to get:

```
>>dir_and_file_string
Test/file.txt

```

I'm assuming that this is a string operation rather than a filesystem operation.

Answer: 
You should use [os.path.relpath](https://docs.python.org/2/library/os.path.html#os.path.relpath)

```
import os
full_path = "/full/path/to/file"
base_path = "/full/path"
relative_path = os.path.relpath(full_path, base_path)

```
```
os.path.sep.join(path_string.split(os.path.sep)[-2:])

```