Batch Renamer that appends Index for Windows 2003

I need a batch file that fill rename this:
lonewolf 2006-06-04 23;00;
lonewolf 2006-06-05 23;00;
quickbooks 2006-06-04 23;30;
quickbooks 2006-06-05 23;30;
showingdesk 2006-05-09 00;00;
showingdesk 2006-05-10 00;00;

into this:

The way I thought of it:
- A for loop that goes through the list
- Grabs the first word of each filename as variable A, appends "-n", where in is increasing starting from 1
- It has to verify when variable A changes, in order to reset the counter back to 1

That's all :).
Thanks guys.
Again it has to be a batch file, and it has to run on Windows 2003.
Who is Participating?
That should do the trick; just run it in the folder where your files are. Note that the script is currently in test mode, it will only display the rename commands it would otherwise run; remove the "ECHO" where indicated to run it for real once you've tested it.

@echo off
set CurrentName=
set /a Index=1
for /f "delims=" %%a in ('dir /b /o:n /a:-d *.zip') do call :process "%%a"
goto :eof

set FullName=%~1
set NewExt=%~x1
for /f "tokens=1 delims=. " %%a in ("%FullName%") do set NewName=%%a
if /i not "%CurrentName%"=="%NewName%" (
  set /a Index=1
  set CurrentName=%NewName%
:: *** Test mode: remove the "ECHO" in front of the following line to run the script for real:
ECHO ren "%FullName%" "%NewName%-%Index%%NewExt%"
set /a Index+=1
goto :eof
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.