0

i am sure this is something obvious, but i cant seem to figure it out, for some reason, the batch file i have pasted below always runs twice instead of once when it hits :rename. Could someone tell me what the issue here is? This is related to the 2 other questions - Looking for a way to execute a batch file once a folder hits 10 files and copy and rename files of a certain extension via batch file

Here is the batch file --- >

rem Counting files...
set /a count = 0
for /f "tokens=*" %%P IN ('dir "H:\" /A /b') do (set /a count += 1)



rem 5 or more files?



if %count% GEQ 5 call :rename



:rename
SET count=1
FOR /f "tokens=*" %%G IN ('dir /b *.jpg') DO (call :rename_next "%%G")

goto:copy

:rename_next
ren "%1" %count%.jpg

Pause
set /a count+=1

goto:eof

:copy
xcopy c:\photo\*.jpg c:\photo\files /Y
Pause
Community
  • 1
  • 1
samsam
  • 27
  • 6

1 Answers1

0

This line:

if %count% GEQ 5 call :rename

is calling :rename. After rename returns, the code continues after this if, which happens to be :rename again.

Replace with this code to see what's happening:

echo before call
if %count% GEQ 5 call :rename
echo after call
icyrock.com
  • 27,952
  • 4
  • 66
  • 85