| 1. |
Solve : renumbering files using .BAT? |
|
Answer» Hi All, 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 |
|