You should be able to use the environment variable %~dp0 to get you the drive and path of the batch file currently running. From there, it's a not-very-efficient method of stripping off the end of that string character by character and building a new string.
For example, the batch file:
@setlocal enableextensions enabledelayedexpansion
@echo off
set olddir=%~dp0
echo Current directory is: !olddir!
if "!olddir:~-1!" == "\" (
set olddir=!olddir:~0,-1!
)
set lastbit=
:loop
if not "!olddir:~-1!" == "\" (
set lastbit=!olddir:~-1!!lastbit!
set olddir=!olddir:~0,-1!
goto :loop
)
set newdir=c:\build\bin\!lastbit!
echo New directory is: !newdir!
endlocal
running as c:\data\src\branch1\qq.cmd returns the following:
Current directory is: C:\data\src\branch1\
New directory is: c:\build\bin\branch1
As to how it works, you can use !xyz:~n,m! for doing a substring of an environment variable, and negative m or n means from the end rather than the beginning. So the first if block strips off the trailing \ if it's there.
The loop is similar but it transfers characters from the end of the path to a new variable, up until the point where you find the \. So then you have the last bit of the path, and it's a simple matter to append that to your fixed new path.