Fixing 'Missing Operator' Error in Batch Script for Renaming JPG Files on Windows

I'm trying to rename image files (JPGs) on a Windows machine. I want to add an incrementing number (e.g., file1.jpg, file2.jpg, etc.) to each filename.

I wrote a batch script using a loop, but I'm encountering a 'Missing operator' error. Here's the relevant part of the script:

setlocal EnableDelayedExpansion
set filename=file
set counter=0
for /f "usebackq delims=*" %i in (`dir /b *.jpg`) do (
    set /a counter+=1
    ren "%i" "%filename%!counter!.jpg"
)


Can anyone help identify the issue causing the error? @Middleware & OS
Was this page helpful?