7

I'm trying to iterate through folders with images to create thumbnails using ImageMagic, and rename thumbnail files with small_ prefix.

when I execute this in single folder, it works great:

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

To loop through subfolders, I just need /R flag:

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

This will result into new name for thumbnail small_c:\images\image.jpg which is wrong :)

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

Thanks.

Andrija
  • 12,383
  • 17
  • 51
  • 75

1 Answers1

16

I think this is may suit your case.

for /R %i in (*.jpg) DO convert %i -thumbnail 30% %~di%~pi%~ni_small%~xi
renick
  • 3,838
  • 2
  • 27
  • 38
  • 1
    I'll just use small_ in front of file name: for /R %i in (*.jpg) DO convert %i -thumbnail 30% %~di%~pismall_%~ni%~xi – Andrija Mar 21 '11 at 20:36
  • 2
    this would not work for me no matter what, until i found in the manual http://ss64.com/nt/for.html that the correct syntax is double-%, e.g.: for /R %%i in (*.jpg) DO convert %%i... – Peter Perháč Jan 14 '15 at 14:06
  • 1
    The double-`%` is only necessary if running the command in a batch file. If running the `for` loop at the command prompt, only a single `%` is required. – naitsirhc Aug 12 '16 at 13:32