Help making simple image convert button script

Hi. I often convert images to webp, and I have a batch script that does exactly that, but recently I've also wanted to resize images before doing the conversion. I've been doing a three step process of resizing with the built in image convert to an intermediary BMP format, deleting the original images, then running my convert script. However, I've done this enough that I feel silly that I don't just make this a single click affair. I could make another batch script and have a button run that, but I wanted to see if I could instead bake the script into a button. Unfortunately I'm not quite figuring it out.

On a batch script this code would work fine, but if I put it in a button and set it to Batch Function it doesn't seem to work, and I don't understand why.

for /R "%~dp0" %%a in ("*.jpg" "*.png" ) do (
    magick convert "%%a" -quality 92 -define webp:method=6 "%%~da%%~pa%%~na.webp"
)

What am I doing wrong here? I just want to loop over all the files, call imagemagick to convert it, and then delete the original file.

I'm also open to some other equally simple way to do this.

Try removing "%~dp0" from the batch function.

ImageMagick works well from a regular command button. The underlying principle is the same. Try it out and see what you like better. You'll find examples on the forum.

Oh, just like that huh. Thanks!