1.

Solve : renumbering files using .BAT?

Answer»

Hi All,
I am having trouble trying to figure out if its is possible to change a sequence of numbered frames using a batch file. I can move and rename OK, but what I need is to move a SERIES of sequentially numbered files (ex: Az_361.tif - Az_720.tif) to a NEW folder and renumber not rename (ex: they are now Az_001.tif - 360.tif).

I have software for this, but it involves selecting the files and specifying the new sequence over and over. I typically need to do 200 of these move and renumber sets at a time.

While I am not exacly a beginner, I haven't spent a LOT of time in DOS recently Any help is appreciated.

TonyQuote from: hamiltony on January 21, 2010, 01:16:56 PM

Move a series of sequentially numbered files (ex: Az_361.tif - Az_720.tif) to a new folder and renumber not rename (ex: they are now Az_001.tif - 360.tif).

The old numbers are part of the file name:AZ_361.tif.
And the new numbers are part of the file name.

You are renaming the files. Copy the files, rename the files with new numbers as part of the name. If all works well, del the ORIGINAL files.

A batch file with a for loop and number generator will do the job.Code: [Select]@echo off

REM ren may misfire with long file names.
REM Use dir /x for short name list
REM C:\>dir /?
rem /X This displays the short names generated for non-8dot3 file
rem names. The format is that of /N with the short name inserted
rem before the long name. If no short name is present, blanks are
rem displayed in its PLACE.


REM Az_361.tif - Az_720.tif) to a new folder and rename
REM (ex: they are now Az_001.tif - 360.tif).

setLocal EnableDelayedExpansion

rem dir /b *.tif > tiffiles.txt

set N=0
for /f "tokens=* delims= " %%a in (tiffiles.txt) do (
set /a N+=1
set var=%%a

ren !var! AZ00!N!.tif
)
dir /b AZ*
dir /b *.tif
Output:

C:\batch> numfiles.bat
.
.
.

AZ004.tif
AZ005.tif
AZ006.tif
AZ007.tif
.
.
.

C:\batch>ren might work better with a shorter name

Instead of:

ren !var! AZ00!N!.tif

use:

ren !var! AZ!N!.tif

Thanks Bill,
This is a big help. I figured out how to generate a batch move list with using C++, but this is what I was trying to do in the first place.

Tony


Discussion

No Comment Found