我正在創建一個批處理文件來初始化便攜式遊戲並在計算機上本地運行以用於性能目的,另一個腳本在完成時將遊戲保存到便攜式驅動器並檢查更新。FOR循環中的IF語句無法正常工作
批處理文件(保存,更新,&清除本地緩存)
@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
聲明循環內,該批處理文件意外退出。
可能是由此行引起的'echo注意:下載更新(!count!)' - 並關閉括號爲根本原因 - 使用捲曲或矩形括號更改它 – npocmaka
@npocmaka謝謝。該腳本起作用。如果您發佈此評論作爲答案,我會接受它。 – Krii