Batch Renamer that appends Index for Windows 2003

Posted on 2006-06-06
Last Modified: 2010-04-18
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.
Question by:gigelkent
    1 Comment
    LVL 82

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
    Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now