Solved Rename.Bat - day difference

January 30, 2013 at 08:28:41
Specs: Windows 7

Good days to you.
I would like to create a batch file (rename.bat), change a file name according to day difference from original.
I hope you can help me for this, thank you.

On 01 JAN 2013, original file name is A0001.dat
on 02 JAN 2013, need rename to A0002.dat
on 03 JAN 2013, need rename to A0003.dat
and so on...A####.dat

#### is day differance for original file name.

See More: Rename.Bat - day difference

Report •

January 30, 2013 at 19:38:35
If #### means the number of days between, that involves date math which is always a mess in batch.

Also, do NOT give a bat the name of an existing command. [RENAME is one]

M2 Golden-Triangle

Report •

January 30, 2013 at 20:25:04
✔ Best Answer
This will probably require a few re-writes... I had to make about a thousand assumptions:
::==== begin batch
@echo off & setlocal
for /f "tokens=*" %%a in ('dir /b a*.dat ^| findstr /i /r "A....\.dat"') do set old=%%~na
:: trim leading zeros prior to math - we don't want octal!
:: {gotta be a better way to do this!}
set hold=%old%
set old=%old:a=A%
set x=%old%
set old=%old:A0=A%
if %x% neq %old% goto :loop

set old=%old:~1%
set /a old +=1
set new=00000%old%
echo ren %hold%.dat A%new:~-4%.dat
ren %hold%.dat A%new:~-4%.dat
::======== end
@M2: crossed in the mail.

Report •

Related Solutions

Ask Question