Extract a given ancestor path form a deeper path in MS-DOS : I have no idea how to get what described here using an MS-DOS batch script:

__pseudo-code__
```
set aPath=C:\just\a\long\path\to\a\file\in\the\file\system
set aDir=file
... some logic here 
echo %result%
```

Should print
```
C:\just\a\long\path\to\a\file
```

__ONLY MS-DOS SOLUTIONS ARE WELCOME__ no Powershell code nor external tools, please. I'm looking for a pure MS-DOS solution.