Solved Syntax error on IF statement for no reason (Batch)

March 17, 2014 at 00:54:50
Specs: Windows 7 Professional, 3.6GHz 16GB
I have this game patcher in batch that I am working on, I decided to add progress bars (Echo [ÛÛ ]). Once done, the IF statements started returning syntax errors, and removing the added lines did not solve the issue. Does anyone know how this could've happened, and how to fix it?

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner


See More: Syntax error on IF statement for no reason (Batch)

Report •


#1
March 17, 2014 at 01:02:28
Here's the code. I have no idea where the actual problem starts, but the IF statements goes crazy at line 59 "if EXIST data ("

@Echo off
setlocal enabledelayedexpansion
set version=1.0
title Normal Day Simulator Patch Installer v%version%
cls
:patcher.main
cd "%~dp0"
cls
Echo Welcome to the NDSimulator Patch Installer
Echo.
Echo Patches found:
dir /b Patches
Echo.
Echo Enter the patch you want to install.
set /p patchSelection=">> "
if NOT EXIST Patches\!patchSelection! (
Echo.
Echo The patch !patchSelection! does not exist.
timeout /t 2 > nul
goto patcher.main
)
cd Patches\!patchSelection!
for /f "tokens=1,2* delims=_" %%A in (patchID.txt) do (
set %%A=%%B
)
:patcher.patchInfo
cls
Echo Patch information:
Echo.
Echo Patch version: %V%
Echo Patch build: %B%
if NOT "%R%"=="" (
Echo Patch requirement: NDSimulator v%R%lpha
)
Echo.
set applyPatch=0
Echo Are you sure you want to apply this patch?
set /p applyPatch=">> "
if /i !applyPatch!==y (
goto patcher.init
)
if /i !applyPatch!==n (
goto patcher.main
)
if !applyPatch!==0 (
Echo Invalid choice.
timeout /t 2 > nul
goto patcher.patchInfo
)
Echo Invalid choice.
timeout /t 2 > nul
goto patcher.patchInfo
:patcher.init
cls
Echo Applying patch v%V%, Please wait...
timeout /NOBREAK 2 > nul
cd "%~dp0"
cd Patches\!patchSelection!

REM ERROR OCCURS HERE

if EXIST data (
cd "%~dp0"
rmdir /s /q data
mkdir data > nul
xcopy /y /q /e "Patches\!patchSelection!\data" "%~dp0\data" > nul
cd Patches\!patchSelection!
)
if EXIST error (
cd "%~dp0"
rmdir /s /q error
mkdir error > nul
xcopy /y /q /e "Patches\!patchSelection!\error" "%~dp0\error" > nul
cd Patches\!patchSelection!
)
if EXIST logs (
cd "%~dp0"
rmdir /s /q logs
mkdir logs > nul
xcopy /y /q /e "Patches\!patchSelection!\logs" "%~dp0\logs" > nul
cd Patches\!patchSelection!
)
if EXIST Saves (
cd "%~dp0"
rmdir /s /q Saves
mkdir Saves > nul
xcopy /y /q /e "Patches\!patchSelection!\Saves" "%~dp0\Saves" > nul
cd Patches\!patchSelection!
)
if EXIST Troubleshooting (
cd "%~dp0"
rmdir /s /q Troubleshooting
mkdir Troubleshooting > nul
xcopy /y /q /e "Patches\!patchSelection!\Troubleshooting" "%~dp0\Troubleshooting" > nul
cd Patches\!patchSelection!
)
if EXIST wIndex (
cd "%~dp0"
rmdir /q /s wIndex
mkdir wIndex > nul
xcopy /y /q /e "Patches\!patchSelection!\wIndex" "%~dp0\wIndex" > nul
cd Patches\!patchSelection!
)
if EXIST wReq (
cd "%~dp0"
rmdir /s /q wReq
mkdir wReq > nul
xcopy /y /q /e "Patches\!patchSelection!\wReq" "%~dp0\wReq" > nul
cd Patches\!patchSelection!
)
if EXIST wTemp (
cd "%~dp0"
rmdir /s /q wTemp
mkdir wTemp > nul
xcopy /y /q /e "Patches\!patchSelection!\wTemp" "%~dp0" > nul
cd Patches\!patchSelection!
)
if EXIST main (
cd "%~dp0"
del /q Launcher.bat
del /q NDSimulator.bat
xcopy /y /q "Patches\!patchSelection!\main\Launcher.bat" "%~dp0" > nul
xcopy /y /q "Patches\!patchSelection!\main\NDSimulator.bat" "%~dp0" > nul
cd Patches\!patchSelection!
)
cd "%~dp0"
cd Patches\!patchSelection!
xcopy /y /q "patchID.txt" "%~dp0\data" > nul
cls
set percentage=100
Echo %percentage% %%
timeout /NOBREAK 2 > nul
cls
Echo Done!
Echo.
Echo Enjoy the new version of Normal Day Simulator!
Echo.
Echo.
Echo *Press any key to exit...*
pause > nul
exit

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner

message edited by RainBawZ


Report •

#2
March 17, 2014 at 07:46:02
✔ Best Answer
Leave ECHO on, and check to see which IF statement is giving you an error.

How To Ask Questions The Smart Way


Report •

#3
March 17, 2014 at 19:42:35
Yes, and I would also add: get rid of all the "flab". Render the code down to the most essential points and work up from there. Also, I've learned the hard way, always put filenames and paths in quotes. F/e, make this snippet and see what happens:
cd "%~dp0"
cd Patches\!patchSelection!

REM ERROR OCCURS HERE - note quotes added to foll line

if EXIST "data" (
echo "%cd%\data" exists
REM since you said it was a syntax error in the IF, then these other (deleted) statements are irrelevant.
) ELSE (echo "%cd%\dat6a" does not appear to be existant.)
cls
Echo Done!


Report •

Related Solutions


Ask Question