Two fundamental issues:
The compound statement must be enclosed in parentheses. In parentheses, changing the value of a variable will NOT be visible if you havenβt done so SETLOCAL ENABLEDELAYEDEXPANSION- and even then you will need to use it! Var! not% var%
So:
SETLOCAL ENABLEDELAYEDEXPANSION
if exist "c:\folder1" (
set Folder1=1
echo !Folder1!
goto install
) else if exist "c:\folder2" (
set Folder2=1
echo !Folder2!
goto Install
) else goto Install
:Install
@ECHO off
if exist "c:\folder1" (
set Folder1=1
goto install
) else if exist "c:\folder2" (
set Folder2=1
goto Install
) else goto Install
:Install
SET folder
@ECHO off
if exist "c:\folder1" set Folder1=1&goto install
if exist "c:\folder2" set Folder2=1&goto Install
:Install
SET folder
:
@ECHO OFF
setlocal
SET "folder1="
SET "folder2="
ECHO.
DIR /b /ad c:\folder*
CALL :test
ECHO.
MD c:\folder1
DIR /b /ad c:\folder*
CALL :test
ECHO.
RD c:\folder1
MD c:\folder2
DIR /b /ad c:\folder*
CALL :test
ECHO.
MD c:\folder1
DIR /b /ad c:\folder*
CALL :test
RD c:\folder1
RD c:\folder2
GOTO :eof
:test
if exist "c:\folder1" set Folder1=1&goto install
if exist "c:\folder2" set Folder2=1&goto Install
:Install
SET folder
SET "folder1="
SET "folder2="
GOTO :eof
.
:
----------No folders
----------Folder 1 only
folder1
Folder1=1
----------Folder 2 only
folder2
Folder2=1
----------Both
folder1
folder2
Folder1=1
,
SET "folder1="
SET "folder2="
, , , , , , , , .