CMD runs command, but in .bat it is not working

I have this command.

for /r "C:\folder" %a in (*.jpg) do magick mogrify -resize 580x320 "%~a"

And it's working in command line, but when I create a .bat file from it then it's not working.


This is the right interpretation.

for /r "C:\folder" %%a in (*.jpg) do magick mogrify -resize 580x320 "%%~a"

I forgot double %%.

Now it's working when I create and use .bat file.