如何将11添加到%% i?

时间:2015-02-18 17:00:42

标签: batch-file batch-rename

我试过

set /p input2=
FOR /L %%i IN (1,1,%input2%) do ren text_%%i.txt worked_%%i+11.txt

它只是尝试将text_1.txt重命名为working_1 + 11.txt 我该怎么做呢?

提前致谢

2 个答案:

答案 0 :(得分:4)

我理解你想要数学加法的问题。所以你需要delayed expansionset /a

@echo off

set /p input2=provide a number
setlocal enableDelayedExpansion
FOR /L %%i IN (1;1;%input2%) do (
 set num=%%i
 set /a nump11=num+11
 ren text_%%i.txt worked_!nump11!.txt
)

答案 1 :(得分:3)

只是为了踢,我决定编写一个不使用延迟扩展但不需要CALL的解决方案。但通常我会像npocmaka那样使用延迟扩展。

@echo off
set /p input2=
set /a end=input2+11
for /f "tokens=1,2 delims=: " %%A in (
  '(for /l %%N in (12 1 %end%^) do @echo %%N^)^|findstr /n "^"'
) do echo ren text%%A.txt worked_%%B.txt