Incrementing a variable in a FOR loop - BAT

Julien -  
barnabe0057 Posted messages 14431 Registration date   Status Contributeur Last intervention   -
Hello,

I would like to increment the variable num. In this case, it always remains at 10. Any idea? The goal is to increment the filename during the copy.

set num=10

setlocal enableDelayedExpansion
for /f "tokens=* " %%o in ('dir C:\Users\XX\Documents\Test\Collect7DAY\Collecte*. /w /b') do set /a num=!num!+1 && copy C:\Users\XX\Documents\Test\Collect7DAY\%%o C:\Users\XX\Documents\Test\Collect7DAY\MAM-S-CORE-01_DaletPlusServer_2\%filename%!num! /v/-y && timeout /t 2 && Echo HERE && Echo VALUE!num!)
endlocal

I have tried a lot of things... But I am not a .bat expert

Need help!
Thank you,

1 réponse

barnabe0057 Posted messages 14431 Registration date   Status Contributeur Last intervention   4 929
 
Hello,

I haven't tested it but it should look like this:

set num=10
set source=%USERPROFILE%\Documents\Test\Collect7DAY
cd /d %source% || exit /b 1

setlocal enableDelayedExpansion

for /f "tokens=* " %%O in ('dir "Collecte*" /b /a-d') do (
set /a num+=1
copy "%%~fO" "%source%\MAM-S-CORE-01_DaletPlusServer_2\%%~nO!num!%%~xO" /v/-y
timeout /t 2
echo ICI & echo VALEUR!num!
)

endlocal


“Artificial intelligence is defined as the opposite of natural stupidity.”
0