我的脚本类似于:
cd <Directory>
set counter = 1
for /r %%f in (*) do (
<Do task>
echo Task completed for file<counter> >> C:\log
counter++
)
我不知道如何使用实际counter
值。如果我使用counter
或者%counter%
它只是回显相同的字符串。在这种情况下我应该如何修改counter
行?
我的脚本类似于:
cd <Directory>
set counter = 1
for /r %%f in (*) do (
<Do task>
echo Task completed for file<counter> >> C:\log
counter++
)
我不知道如何使用实际counter
值。如果我使用counter
或者%counter%
它只是回显相同的字符串。在这种情况下我应该如何修改counter
行?
SET
/A
如果要计算数学表达式,必须使用 with 。您还需要首先通过键入SETLOCAL ENABLEDELAYEDEXPANSION
作为第一行来启用延迟扩展。**FOR**
在最后一次迭代发生之前,不会在循环内进行评估。但是我修改了批处理文件,以便 Counter 的值在每次迭代中递增。
SETLOCAL ENABLEDELAYEDEXPANSION
@echo off
set /a counter=1
for /r %%f in (*) do (
echo Task Completed for file !counter! >> c:\log
set /a counter=!counter!+1
)
SET /A Variable_Number Math_symbol = Step(s)
set /a Var_Num+=1
-> Num_Var = Num_Var + 1(步长)
set /a Var_Num-=1
-> Num_Var = Num_Var - 1(步骤)
set /a Var_Num*=2
-> Num_Var = Num_Var x 2(步数)
set /a Var_Num/=2
-> Num_Var = Num_Var:2(步数)
在一个循环中:
@echo off
set counter=0
:start-loop
set /a counter+=1
echo %counter% times...
:: or/and
echo %counter% times... >> %USERPROFILE%\Desktop\log.txt
timeout /t 1 >nul
goto :start-loop
你的例子:(在'FOR'循环中)
SETLOCAL ENABLEDELAYEDEXPANSION
@echo off
set /a counter=1
for /r %%f in (*) do (
echo Task Completed for file !counter! >> C:\log.txt
echo Path to File: [ %%f ] >> C:\log.txt
set /a counter+=1
)