With Path1
being later concatenated with other strings, first double quote should be left to variable name and not after the equal sign as this makes a big difference, see How to set environment variables with spaces? and Why is no string output with 'echo %var%' after using 'set var = text' on command line?
So at top of your batch file there should be:
REM Enter here you program path:
set "ProgramPath=C:\folder1\folder2"
In the batch file you can use string substitutions to make sure the environment variable ProgramPath
holds the path without double quotes and without a backslash at end.
if not defined ProgramPath goto InvalidProgPath
set "ProgramPath=%ProgramPath:"=%"
if not defined ProgramPath goto InvalidProgPath
if "%ProgramPath:~-1%" == "\" set "ProgramPath=%ProgramPath:~0,-1%"
if not defined ProgramPath goto InvalidProgPath
if not exist "%ProgramPath%\" goto InvalidProgPath
rem Other commands as shown below.
mkdir "%ProgramPath%\plugins"
copy "%Path2%" "%ProgramPath%\plugins\plugin.dll"
"%ProgramPath%\program.exe"
goto :EOF
:InvalidProgPath
echo The program path as defined with ProgramPath at top of batch file
echo %~f0
echo is invalid. Please correct the path.
echo/
pause
The second command line replaces all double quotes in value of ProgramPath
by nothing, i.e. all double quotes are removed from program path string.
The fourth line compares case-sensitive the last character of value of ProgramPath
with a backslash and if this character is a backslash, ProgramPath
is set again with all characters with exception of last character.
In the remaining batch file you have to enclose the concatenated strings in double quotes.
By the way: If the program path is the path of the folder containing the batch file, then all needed at top is:
set "ProgramPath=%~dp0"
set "ProgramPath=%ProgramPath:~0,-1%"
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
... explains %~dp0
... drive and path of argument 0 which is the batch file itself always ending with a backslash and %~f0
... full file name of argument 0 with file extension and path.
copy /?
echo /?
goto /?
if /?
mkdir /?
pause /?
rem /?
set /?