Using python, I have the last parts of paths to existing files, like that:

```
sub_folder1/file1.txt
sub_folder2/file120.txt
sub_folder78/file99.txt

```

Note, that these paths are not the relative paths to the current folder I am working in, e.g., this `pandas.read_csv('sub_folder1/file1.txt')` would through a non-existing-file error. Nevertheless, I know all the files have the same base directory `base_dir`, but I don't know the absolute path. This means a file could be located like this:

```
base_dir/inter_folder1/sub_folder1/file1.txt

```

Or like this:

```
base_dir/inter_folder7/inter_folder4/.../sub_folder1/file1.txt

```

**Is there a function that returns the absolute path, when given the last part of the path and the base directory of a file (or equivalently, finding the intermediate folders)?** Should be looking like that:

```
absolut_path = some_func(end_path='bla/bla.txt', base_dir='BLAH')

```

I thought `pathlib` might have a solution, but couldn't find anything there. Thanks

---

I need this to do something like the below:

```
for end_path in list_of_paths:
    full_path = some_func(end_path=end_path, base_dir='base_dir')
    image = cv2.imread(full_path)

```