I need Windows CMD to loop through folders in a directory and execute a command to convert webp to png on each one

I have always use this command line to convert .webp to .png:

for %f in (*.webp) do dwebp.exe  "%f" -o "%~nf.png"

Works like a charm for single folders, but now I have several .webp files that I need to convert inside several folders in the same directory, example:


And so on… I need help on how to do this.

Thanks in advance.


1. Add /R Recurse, loop through files (Recurse subfolders):

2. Replace output -o "%~nf.png" file to -o "%~dpnf.png"

for /R %f in (*.webp) do dwebp.exe  "%f" -o "%~dpnf.png"
  • Or…
for /R "C:IMG" %f in (*.webp) do dwebp.exe  "%f" -o "%~dpnf.png"

Read more For Loop and For /R Loop