The problem here is to create new log if one doesn't exist, or append to one if it does (providing it isn't too large) The problem is compounded by the use of nested variables beginning with %USERNAME% then %LOGFILE% then APPENDORNEW, trying to form APPENDORNEW into a command.
REM Set way back at the beginning of the code several sub labels back
setlocal DisableDelayedExpansion
.
.
.
Set LOGFILE=C:\Users\%USERNAME%\Documents\Logs\X.log
REM Does the logfile exist already?
REM Adjust redirection operators to create new log or appends to old log.
REM Quotes make no difference
If exist !%LOGFILE%! (set "_APPENDORNEW=^>^>"
) else (set "_APPENDORNEW=^>")
@echo on
REM This displays nothing (as expected?)
echo %_APPENDORNEW%
set /p APPENDORNEW=!%_APPENDORNEW%%LOGFILE%!
REM The display is just '\Users\%USERNAME%\Documents\Logs\X.log'
REM with the username value- but what happened to the 'C:'?
echo %APPENDORNEW%
%APPENDORNEW%: (
REM This is the command that is supposed to go >LOGFILE or >>LOGFILE
REM The cursor "hangs" here before enter resumes execution
REM The colon was suggested somewhere else- but doesn't factor here
echo Start time is: %date% %TIME%
REM Do Commands
REM This bracket is grouped within sub labels.
)