如何带走变量? (批量)

时间:2017-10-30 19:11:43

标签: batch-file variables

我正在制作一个快速通过保护的批处理(以后会使它成为.exe)并且我想在try变量达到0时将其删除,但我无法弄清楚如何检查try是否为0,或者从变量中取出,快速示例:

set %tries%=3
set /P c=Please Enter The Password; You Have %tries% Attempts Remaining
if /I "%c%" EQU "Pass" goto :command_hub

(insert a thing that checks if 0 and then takes 1 if not)

goto :delete
:delete
(goto) 2>nul & del "%~f0"

1 个答案:

答案 0 :(得分:0)

set %tries%=3
set /P c=Please Enter The Password; You Have %tries% Attempts Remaining
if /I "%c%" EQU "Pass" goto :command_hub

(insert a thing that checks if 0 and then takes 1 if not)

应该是

set /a tries=3
:retry
set /P c=Please Enter The Password; You Have %tries% Attempts Remaining
if /I "%c%" EQU "Pass" goto command_hub
set /a tries-=1
if %tries% gtr 0 goto retry

设置%tries%设置一个名为当前尝试内容的变量

set / a执行算术运算。分配像3这样的数值时,它是可选的。

从文档提示中查看set /?

goto :label命令有效但不需要冒号除了 goto :eof的具体情况,这意味着'走到尽头文件'(终止例程)标识:eof已被理解,不应编程。