To loop recursively through a folder in windows cmd to rename the file

I am trying to iterate over image folders to create thumbnails using ImageMagic and rename thumbnail files with small_ prefix.

when I execute this in one folder, it works fine:

 FOR %a in (*.jpg) DO convert %a -thumbnail 30% small_%a 

To iterate over subfolders, I just need the / R flag:

 FOR /R %a in (*.jpg) DO convert %a -thumbnail 30% small_%a 

This will result in a new name for the thumbnail small_c:\images\image.jpg , which is incorrect :)

How can I get the small_ prefix in the file name when recursing through subfolders in the script, i.e. from c:\images\image.jpg to c:\images\small_image.jpg ?

Thanks.

+6
command-line image recursion rename windows-scripting
source share
1 answer

I think this can satisfy your case.

 for /R %i in (*.jpg) DO convert %i -thumbnail 30% %~di%~pi%~ni_small%~xi 
+11
source share

All Articles