Search code examples
batch-filebatch-rename

How do I add 11 to %%i?


I tried

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

and it just tries to rename text_1.txt to worked_1+11.txt How do I do it properly?

Thanks in advance


Solution

  • As I understand the question you want a mathematical addition.So you'll need delayed expansion and set /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
    )