Computing.Net > Forums > Programming > Batch Rename with Incremental numbe

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Rename with Incremental numbe

Reply to Message Icon

Name: redwax
Date: December 13, 2007 at 12:01:46 Pacific
OS: xp
CPU/Ram: ath64,4000,1024
Product: na
Comment:

Hi, I have a batch files which converts some images using image magick. It does a small amount of renaming already, however, It would be really useful if it could append an incrementing number. This is what I have so far:

:RUN_PRODUCT
mkdir products
cd products
mkdir small
mkdir large
cd ../
for %%f IN (*.jpg) do convert %%f -strip -resize 150x150 -quality 70 products/small/%%f
for %%f IN (*.jpg) do convert %%f -strip -resize 600x600 -quality 95 products/large/%%~Nf_LRG.jpg
goto start

I would ideally like to insert the 2 digit incremental prior to the _LRG part of the name, so have blah_01_LRG.jpg, blah_02_LRG.jpg etc.

Any help would be greatly appreciated. cheers




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: December 13, 2007 at 12:52:18 Pacific
Reply:

Start your batch by coding

@Echo Off
SetLocal EnableDelayedExpansion

then

Set index=0
for %%f IN (*.jpg) do (
Set /A index+=1
If !index! lss 10 Set index=0!index!
Set index=_!index!
convert %%f -strip -resize 600x600 -quality 95 products/large/%%~Nf!index!_LRG.jpg
Set index=!index:_0=!
Set index=!index:_=!
)


0

Response Number 2
Name: redwax
Date: December 13, 2007 at 13:03:51 Pacific
Reply:

Amazing, thank you so much, that did just the job!


0

Response Number 3
Name: Blasterman
Date: January 1, 2008 at 11:29:52 Pacific
Reply:

Note that the solution won't work in Windows 9x,ME, or DOS.


All the OSes I use:
Windows XP, Windows 98, MS-DOS 6.22, OpenBSD 2.6, DLX Linux. I have 4 computers, one of which is emulated.


0

Response Number 4
Name: User123456789
Date: January 3, 2008 at 04:24:17 Pacific
Reply:

Interesting, this "set /a" functionality ...

Hi there.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Rename with Incremental numbe

Batch rename w/ incremental number www.computing.net/answers/programming/batch-rename-w-incremental-number/17035.html

A problem with batch renaming www.computing.net/answers/programming/a-problem-with-batch-renaming/14963.html

Batch Rename www.computing.net/answers/programming/batch-rename-/12849.html