Rename and Sequentially number files

Microsoft Windows xp professional w/serv...
April 28, 2010 at 16:25:20
Specs: Windows XP
I hope someone can help. I need a batch file to rename and sequentially number a series of files which look as follows

A117455S.AD117544.614412
A117455S.AD117544.626780
A117455S.AD217544.692348
A117455S.AD217544.1216582

The second part of the filename contains AD1, AD2, etc up to 8 - this identifies a region and there are 4 or 5 files for each region. The last part of the filename is a random number of either 6 or 7 digits.

I need to change the filenames to be something like
AD1's = NSW_Claims_001.txt, NSW_Claims_002.txt, etc.
AD2's = VIC_Claims_001.txt......

Hope this makes sense...have tried and googled for 3 days and cant quite get there.
Any help appreciated.


See More: Rename and Sequentially number files

Report •

#1
April 28, 2010 at 16:35:32
where are you going to get, or how derive, these:
NSW, VIC
are they in the files themselves? or in a masterfile somewhere? some kind of xlat table will be needed.

Report •

#2
April 28, 2010 at 16:38:09
The 2nd part of the filename AD117544, AD217544, AD317544 determines whether they are NSW, VIC etc. AD1????? = NSW, AD2????? = VIC, etc

Report •

#3
April 30, 2010 at 14:57:09
@echo off & setLocal EnableDELAYedeXpansion

set N=
for /f "tokens=* delims= " %%a in ('dir/b/a-d ^| find "AD1"') do (
set /a N+=1
set Q=00!N!
echo ren "%%a" "NSW_Claims_!Q!.txt"
)

set N=
for /f "tokens=* delims= " %%a in ('dir/b/a-d ^| find "AD2"') do (
set /a N+=1
set Q=00!N!
echo ren "%%a" "VIC_Claims_!Q!.txt"
)


:: and so on


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
May 2, 2010 at 16:49:25
Fantastic....it works, thank you so so much

Report •

Ask Question