Please Help renaming files

July 16, 2009 at 19:31:16
Specs: Windows XP
Hi Everyone

I’m tiring to make batch file to rename oeminfo.ini to oeminfoBAK.ini and if it exist to auto rename oeminfoBAK1.ini and BAK2 and BAK3 and so on..
I would also like to rename oemlogo.bmp to oemlogoBAK.bmp at the same time.

if exist c:\windows\system32\oeminfoBAK.ini ren c:\windows\system32\oeminfo.ini oeminfoBAK2.ini

if exist c:\windows\system32\oeminfo.ini ren
c:\windows\system32\oeminfo.ini oeminfoBAK.ini

if exist c:\windows\system32\oemlogoBAK.bmp ren c:\windows\system32\oemlogo.bmp oemlogoBAK2.bmp

if exist c:\windows\system32\oemlogo.bmp ren c:\windows\system32\oemlogo.bmp oemlogoBAK.bmp

It works only once before errors. I know there is a better way.

Any help would be deeply appreciated.

Thanks in advance.

See More: Please Help renaming files

Report •

July 16, 2009 at 20:28:08
I imagine the errors come up on the 2nd run thru because the file name to which you are trying to rename the file now exisits. The following should work for 9 backup copies. You can expand it if needed. (File names shortened because it is easier to keep track of in the tiny reply box.)


If Exist infoBak9.ini Del infoBak9.ini
If Exist infoBak8.ini Copy infoBak8.ini infoBak9.ini
If Exist infoBak7.ini Copy infoBak7.ini infoBak8.ini
If Exist infoBak6.ini Copy infoBak6.ini infoBak7.ini
If Exist infoBak5.ini Copy infoBak5.ini infoBak6.ini
If Exist infoBak4.ini Copy infoBak4.ini infoBak5.ini
If Exist infoBak3.ini Copy infoBak3.ini infoBak4.ini
If Exist infoBak2.ini Copy infoBak2.ini infoBak3.ini
If Exist infoBak1.ini Copy infoBak1.ini infoBak2.ini
If Exist info.ini Copy info.ini infoBak1.ini

Report •

July 17, 2009 at 08:50:22
@echo off & setLocal EnableDELAYedExpansion

pushd c:\windows\system32

if not exist oeminfo1.ini ren oeminfo.ini oeminfo1.ini && goto :eof

for /L %%a in (9 -1 1) do (
if exist oeminfo%%a.ini (
set /a N=%%a+1
goto :done
ren oeminfo.ini oeminfo!N!.ini

If at first you don't succeed, you're about average.


Report •

Related Solutions

Ask Question