似乎有人建议在Windows批处理脚本中使用双引号if if:
IF "%FLAG%"=="1" (do something)
但是,在我的情况下,我发现使用双引号可能会导致脚本在比较时失败。任何人都可以看到这里可能出现的问题吗?
PS:我在脚本中SETLOCAL ENABLEDELAYEDEXPANSION
。
编辑: 当ECHO%FLAG%为1时,该语句甚至失败。
EDIT2: 这是我的剧本。
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set CFG=C:\config
set LOBBYLIST=%CFG%\serverlist_lobby_server.txt
set DBDAEMONLIST=%CFG%\serverlist_daemon_server.txt
set LIST=
set FOLDER=
set /p OP= Delete 1.Lobby, 2.dbdaemon, All? (1,2,a)
:BEGIN
if %OP%==1 (GOTO DELETE_LOBBY_DUMP)
if %OP%==2 (GOTO DELETE_DBDAEMON_DUMP)
GOTO END
:DELETE_LOBBY_DUMP
set LIST=%LOBBYLIST%
set FOLDER=LobbyServer
GOTO START_DELETE
:DELETE_DBDAEMON_DUMP
set LIST=%DBDAEMONLIST%
set FOLDER=DBDaemonServer\Lobby
GOTO START_DELETE
:DELETE_ALL
set /a OP = OP + 1
GOTO BEGIN
:START_DELETE
for %%b in (%LIST%) do (
echo %%b
for /f %%a in (%%b) do (
echo %%a
dir \\%%a\c$\Services\%FOLDER%\*.dmp | find "dmp"
dir \\%%a\c$\WINDOWS\PCHEALTH\ERRORREP\UserDumps\*.hdmp | find "hdmp"
))
echo.
echo.
if %isAll%==1 (set isContinue=y
) ELSE (set /p isContinue= Continue? (y/n)
)
if %isContinue%==y (
for %%b in (%LIST%) do (
echo %%b
for /f %%a in (%%b) do (
echo %%a
del \\%%a\c$\Services\%FOLDER%\*.dmp
del \\%%a\c$\WINDOWS\PCHEALTH\ERRORREP\UserDumps\*.hdmp
)
)
)
if %isAll%==1 (GOTO DELETE_ALL)
GOTO END
:END
pause
答案 0 :(得分:0)
延迟扩展与此无关。
比较失败时%FLAG%
的值是多少,即ECHO %FLAG%
输出的是什么?