Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For loop recursively through folder in windows cmd for file rename

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.

like image 572
Andrija Avatar asked Mar 21 '11 20:03

Andrija


People also ask

How do I batch rename a folder?

You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.

How do I traverse a folder in command prompt?

If you know the name of the directory you want to move into, you can also type cd\ and the directory name. For example, to move into C:\Windows>, type cd\windows at the prompt.


1 Answers

I think this is may suit your case.

for /R %i in (*.jpg) DO convert %i -thumbnail 30% %~di%~pi%~ni_small%~xi
like image 133
renick Avatar answered Sep 20 '22 03:09

renick