First problem: a label within a block (a parenthesised series of statements) terminates the block (this may be version-dependent) Hence, the commands following the label will be executed regardless of what the result of the remainder of the block is.
Second problem: the routine :skip is terminated by an unbalanced ). This may be harmless in itself, but it does not terminate the routine. call :skip will continue to an exit or end-of-file before returning.
Third problem: Within a block statement (a parenthesised series of statements), the entire block is parsed and then executed. Any %var% within the block will be replaced by that variable's value at the time the block is parsed - before the block is executed - the same thing applies to a FOR ... DO (block).
Hence, IF (something) else (somethingelse) will be executed using the values of %variables% at the time the IF is encountered.
Two common ways to overcome this are 1) to use setlocal enabledelayedexpansion and use !var! in place of %var% to access the changed value of var or 2) to call a subroutine to perform further processing using the changed values.
So - in your case, the second if %errorlevel% == 0 will applt the value of errorlevel at the time the very first if in the snippet you show us was encountered, not the changed value depending on the processing.
Next problem is that you are excuting the for/f on ftp.txt and appear to do nothing with the data gathered from ftp.txt - %%a is not used at all in the routine, all it does is attempt to call :skip once for each line in ftp.txt.
So-
if %errorlevel% == 0 (
start /wait /d "%folder%"\test setup.exe
if not errorlevel 1 (call :skip)
)
goto :eof
:skip
rd /s /q "%location%"
rd /s /q "%folder%"\agent
goto :eof
may do the job, assuming that errorlevel is set to non-zero if the uninstallation is cancelled. Note that the format if [not] errorlevel n applies to the run-time value of errorlevel whereas if %errorlevel% == 0 applies to the parse-time value.
Without knowledge of what ftp.txt and %%a are supposed to be used for, I've no idea what to do with them...