Reputation: 907
I am creating a batch file to initialize a portable game and run it locally on a computer for performance purposes, and another script to save the game to the portable drive when finished and check for updates.
Batch File (save, update, & clear local cache)
@echo off
title Minecraft - Save
echo [%date%^|%time%]
echo NOTICE: Initializing Minecraft ...
if exist %appdata%\.minecraft (
:: Save World
echo NOTICE: Directory "%appdata%\.minecraft" found.
echo NOTICE: Saveing world files ...
echo ^*^*^*^*^*^*^*^*^*^*^* [%date%^|%time%] ^*^*^*^*^*^*^*^*^*^*^* >> %cd%\logs\save.log
echo Copying files ... >> logs\save.log
xcopy /e /y %appdata%\.minecraft\saves %cd%\.minecraft\saves\ >> %cd%\logs\save.log
echo Complete! >> %cd%\logs\save.log
:: Get Updates
echo NOTICE: Checking for updates ...
setlocal EnableDelayedExpansion
set /a count=0
for /d %%d in (%appdata%\.minecraft\versions\*) do (
rem @echo !count! - %%d
if not !count!==0 (
echo NOTICE: Downloading update (!count!) ...
echo ^*^*^*^*^*^*^*^*^*^*^* [%date%^|%time%] ^*^*^*^*^*^*^*^*^*^*^* >> %cd%\logs\update.log
echo Update found. Copying files... >> %cd%\logs\update.log
xcopy /e /y %%d %cd%\.minecraft\versions\ >> %cd%\logs\update.log
echo Complete! >> %cd%\logs\update.log
)
set /a count+=1
)
:: Clear Local Files
echo NOTICE: Clearing file cache ...
rd /s /q %appdata%\.minecraft
)
:: ERRORLEVEL
if not exist %appdata%\.minecraft (
echo ERROR: Destination directory not found.
echo NOTICE: Minecraft save unsuccessful!
goto end
)
echo NOTICE: Minecraft save successful!
:end
ping 1.1.1.1 -n 10 -w 1 >> nul
exit
The FOR
loop works fine but when I put an IF
statement inside of the loop, the batch file quits unexpectedly.
Upvotes: 1
Views: 53
Reputation: 57252
might be caused by this line echo NOTICE: Downloading update (!count!)
- and closing bracket to be root cause - as it is taken for closing of IF condition. Change it with curly or rectangular brackets
Upvotes: 2