我正在创建一个批处理文件来初始化便携式游戏并在计算机上本地运行它以达到性能目的,另一个脚本在完成后将游戏保存到便携式驱动器并检查更新。
批处理文件(保存,更新和清除本地缓存)
@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
FOR
循环工作正常但是当我在循环中放入IF
语句时,批处理文件意外退出。
答案 0 :(得分:2)
可能由此行echo NOTICE: Downloading update (!count!)
引起 - 并且结束括号是根本原因 - 因为它是关闭IF条件。用花括号或矩形括号改变它