Sunday, January 12, 2020

windows 7 - How do I write a batch script that iterates through all png files in all subfolders and does an action?



I'm looking to build a small batch script that executes the command line of pngout.exe



So far I've got only this down




for %i in (*.png) do "g:\myfiles\_pngout.exe" "%i" /s0 /c6


However, for that to work I have to manually go to each folder where the pngs are and open up a cmd window from Win7 then copy and paste that line.



What I want is for that line to work say in C:\MyPNGs and it's sub-folders, like C:\MyPNGs\Avatars etc., it should iterate through all pngs and every time execute that "g:\myfiles\_pngout.exe" "%i" /s0 /c6



Any ideas?


Answer




You can use the following command from a dosprompt:



for /r %f in (*.png) do _pngout.exe "%f"


or the following inside a batch file:



for /r %%f in (*.png) do _pngout.exe "%%f"



For /r also has support to give a start directory. Otherwise it'll use the current directory and get every file in all subdirectories that match your filemask.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...