Q:

Appending text to variable in batch scripting

Appending filename to file path input by the user not working.
I am getting a file path from the user and want to append the filename I want opened. After this I want to 'start' the file. However it is not working the way I expect it to. Can someone help?
@ echo off
if exist clientshutdown3.exe (
start clientshutdown3.exe) else (
set /p path= Enter path of pdf file:
start %path%\lor.pdf
)
pause

A:

Couple of things. You need to wrap paths in double quotes to eliminate possible whitespace. Also, because we set variables inside of a loop (codeblock), it is best we use delayedexpansion.
Lastly and most importantly, NEVER set a variable name which exists as a system environment variable. Here, path will break your actual path, and commands will no longer work, so instead create a non existing name like mypath.
@echo off
setlocal enabledelayedexpansion
if exist clientshutdown3.exe (
    start clientshutdown3.exe
 ) else (
    set /p "mypath=Enter path of pdf file: "
    start "" "!mypath!\lor.pdf"
)
pause

You could also get away without delayedexpansion by moving the start section to outside of the codeblock.
@echo off
if exist clientshutdown3.exe (
    start clientshutdown3.exe
 ) else (
    set /p "mypath=Enter path of pdf file: "
)
if defined mypath start "" "%mypath%\lor.pdf"
pause

