File increment in batch file

I'm looking into a batch file for a file backup.  It's pretty straight forward, but I know nothing about batch files beyond the basics.

Basically every night I will have a file created called pos.dat

What I'd like to do is increment all previous files by one before placing the dat file while keeping only 100 dat files

      Delete previous pos100.dat
      rename pos99.dat to pos100.dat
      rename pos98.dat to pos99.dat
      rename pos97.dat to pos98.dat
      rename pos01.dat to pos02.dat
      rename previous days pos.dat pos01.dat
      create new pos.dat

I know I can do this with a 100+ line batch file, but I did't know if there was a better way to do this with variables.

Thanks for your help!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harisha M GEngineerCommented:
Hi, it would be better if you have pos1 instead of pos01

Assuming that you change it, here is a code which does it:

Put this in a file, and name it as something.bat


DEL pos100.bat
FOR /l %%i IN (99,-1,1) DO (
  SET /a j=%%i+1
  REN pos%%i.bat pos!j!.bat

You now need to create the new file manually


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RyanMielkeAuthor Commented:

The only reason I was looking at pos01 instead of pos1 was to keep it clean if we were looking at a directory listing, but that's fine.

Thanks for your help!

Harisha M GEngineerCommented:
Glad I could help :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.