Overwrite variable from routine
===

I've got this here batch, and I'm trying to get the parent directory to stick.

    @echo off

    SET CWD=

    :process
    if [%1] == [] goto end
    SET MASTER_DIR="%~f1"
    
    rem Change to say, E:\DVD_LIBRARY\Rips
    cd /d %MASTER_DIR%
    for /R %%D IN (\) DO (

        rem Temporarily change to the subdir, such as E:\DVD_LIBRARY\Rips\SIN_CITY\
        pushd %%D
        for /F "usebackq" %%Z in (`dir /b *.vob 2^>NUL`) DO (
            if exist %%~fZ (

                rem Get this parent directory to store the log file in (eventually)
                CALL :resolve "%%D\.." CWD

                rem Nada.
                echo: %CWD%
            )
        )
        popd
    )
    shift
    goto process

    :resolve
    SET %2=%~f1
    goto :EOF

In the `:resolve` routine, I'm getting the value I want.  Back in this block:

    if exist %%~fZ (
        CALL :resolve "%%D\.." CWD
        echo: %CWD%
    )

I'm getting nothing.

Any ideas why this isn't sticking, or a better way? I've scoured google and found this technique and some others like it here, but I don't know why the value isn't translating after the `CALL`.