bat 文件是 运行 "if" 在获取输入参数之前检查
bat file is running "if" check before getting input parameter
将其放入名为 "mybat.bat" 的文件中
(放在 c:\temp\
不要把它放在 c:\windows)
set __rightFolder=.
del "%__rightFolder%\system.ini.copy"
If NOT exist "%__rightFolder%\system.ini.copy" (
copy "%windir%\system.ini" "%__rightFolder%\system.ini.copy"
ECHO "%__rightFolder%\system.ini.copy"
SET /P AREYOUSURE="Do you want to run the dir command on '%__rightFolder%\system.ini.copy'"
IF /I "%AREYOUSURE%" EQU "Y" (
dir "%__rightFolder%\system.ini.copy"
)
)
PAUSE
当我 运行 这个简单的脚本时, "IF /I" 在我输入任何内容之前 运行ning。
注意,我有一个很长的问题,问题周围有引号。
这可能很简单,但我 .bat skillzz 很臭。
这是我的输出。
C:\Temp>set __rightFolder=.
C:\Temp>del ".\system.ini.copy"
Could Not Find C:\Temp\system.ini.copy
C:\Temp>If NOT exist ".\system.ini.copy" (
copy "C:\Windows\system.ini" ".\system.ini.copy"
ECHO ".\system.ini.copy"
SET /P AREYOUSURE="Do you want to run the dir command on '.\system.ini.copy'"
IF /I "" EQU "Y" (dir ".\system.ini.copy" )
)
1 file(s) copied.
".\system.ini.copy"
Do you want to run the dir command on '".\system.ini.copy"'y
C:\Temp>PAUSE
Press any key to continue . . .
所以我输入了 'y',但它没有执行 "dir" 命令。
永无止境的故事...EnableDelayedExpansion
Delayed Expansion will cause variables to be expanded at execution
time rather than at parse time, this option is turned on with the
SETLOCAL
command. When delayed expansion is in effect variables may
be referenced using !variable_name!
(in addition to the normal
%variable_name%
)
已修补:
set __rightFolder=.
del "%__rightFolder%\system.ini.copy"
If NOT exist "%__rightFolder%\system.ini.copy" (
copy "%windir%\system.ini" "%__rightFolder%\system.ini.copy"
ECHO "%__rightFolder%\system.ini.copy"
SET /P "AREYOUSURE=Do you want to run the dir command on '%__rightFolder%\system.ini.copy' "
SETLOCAL enabledelayedexpansion
IF /I "!AREYOUSURE!" EQU "Y" (
dir "%__rightFolder%\system.ini.copy"
)
ENDLOCAL
)
PAUSE
将其放入名为 "mybat.bat" 的文件中 (放在 c:\temp\ 不要把它放在 c:\windows)
set __rightFolder=.
del "%__rightFolder%\system.ini.copy"
If NOT exist "%__rightFolder%\system.ini.copy" (
copy "%windir%\system.ini" "%__rightFolder%\system.ini.copy"
ECHO "%__rightFolder%\system.ini.copy"
SET /P AREYOUSURE="Do you want to run the dir command on '%__rightFolder%\system.ini.copy'"
IF /I "%AREYOUSURE%" EQU "Y" (
dir "%__rightFolder%\system.ini.copy"
)
)
PAUSE
当我 运行 这个简单的脚本时, "IF /I" 在我输入任何内容之前 运行ning。 注意,我有一个很长的问题,问题周围有引号。
这可能很简单,但我 .bat skillzz 很臭。
这是我的输出。
C:\Temp>set __rightFolder=.
C:\Temp>del ".\system.ini.copy"
Could Not Find C:\Temp\system.ini.copy
C:\Temp>If NOT exist ".\system.ini.copy" (
copy "C:\Windows\system.ini" ".\system.ini.copy"
ECHO ".\system.ini.copy"
SET /P AREYOUSURE="Do you want to run the dir command on '.\system.ini.copy'"
IF /I "" EQU "Y" (dir ".\system.ini.copy" )
)
1 file(s) copied.
".\system.ini.copy"
Do you want to run the dir command on '".\system.ini.copy"'y
C:\Temp>PAUSE
Press any key to continue . . .
所以我输入了 'y',但它没有执行 "dir" 命令。
永无止境的故事...EnableDelayedExpansion
Delayed Expansion will cause variables to be expanded at execution time rather than at parse time, this option is turned on with the
SETLOCAL
command. When delayed expansion is in effect variables may be referenced using!variable_name!
(in addition to the normal%variable_name%
)
已修补:
set __rightFolder=.
del "%__rightFolder%\system.ini.copy"
If NOT exist "%__rightFolder%\system.ini.copy" (
copy "%windir%\system.ini" "%__rightFolder%\system.ini.copy"
ECHO "%__rightFolder%\system.ini.copy"
SET /P "AREYOUSURE=Do you want to run the dir command on '%__rightFolder%\system.ini.copy' "
SETLOCAL enabledelayedexpansion
IF /I "!AREYOUSURE!" EQU "Y" (
dir "%__rightFolder%\system.ini.copy"
)
ENDLOCAL
)
PAUSE