how would I do that with regular variables?
Essentially you are splitting a string into two parts: (1) From the start to the final token delimiter, (2) the rest. Since dealing with drives, paths and filenames is a pretty common task, cmd.exe has this built in.
One way is to get the ordinary variable into a FOR metavariable...
@echo off
set var=C:\Documents and Settings\User\My Documents\folder_a\b.txt
for /f "tokens=*" %%A in ("%var%") do set DriveAndPath=%%~dpA
echo %DriveAndPath%
...or pass it to a called label "subroutine"
@echo off
goto start
:getpath
set DriveAndPath=%~dp1
goto :eof
:start
set var=C:\Documents and Settings\User\My Documents\folder_a\b.txt
call :getpath "%var%"
echo %DriveAndPath%
You can have the "subroutine" anywhere in the script e.g. at the end but you need to be alert to ensure, with gotos or some other method, that you don't arrive at it by mistake.
The %~n and %~x modifiers work on URLs as well. (The others do not give very useful values)
Note that the string can be a fictitious one. Neither the file "C:\Documents and Settings\User\My Documents\folder_a\b.txt" nor its drive, path, folder, name, extension etc, have to actually exist. Using the date and size modifiers on a nonexistent file will return null (blank) results.