If statement 在批处理脚本中使用IF语句
我是批处理编程新手。我正在尝试在批处理脚本中使用IF条件。代码如下所示If statement 在批处理脚本中使用IF语句,if-statement,batch-file,If Statement,Batch File,我是批处理编程新手。我正在尝试在批处理脚本中使用IF条件。代码如下所示 :rmfile :: removes the file based on it's age. :: SETLOCAL set file=%~1 set age=%~2 set thrshld_days=40 if %age% LSS 40 echo.%file% is %age% days old EXIT /b 现在的问题是,即使一个文件的年龄超过40岁,我也会把它打印出来。
:rmfile
:: removes the file based on it's age.
::
SETLOCAL
set file=%~1
set age=%~2
set thrshld_days=40
if %age% LSS 40
echo.%file% is %age% days old
EXIT /b
现在的问题是,即使一个文件的年龄超过40岁,我也会把它打印出来。这实际上是不应该发生的
在这方面请帮助我…谢谢 将其放在一行上:
if %age% LSS 40 echo.%file% is %age% days old
或使用块分隔符:
if %age% LSS 40 (
echo.%file% is %age% days old
)
被解释为具有空主体(第一行)和无条件的echo
(第二行)的条件表达式。您需要将它们放在一行上:
if %age% LSS 40 echo.%file% is %age% days old
或者使用parens创建块(但开口括号必须与if
在同一行上):
我按照建议尝试了帕伦斯,但没有成功:(每个文件都会打印回音声明.)。。
if %age% LSS 40 echo.%file% is %age% days old
if %age% LSS 40 (
echo.%file% is %age% days old
)