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 and the same way.
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.
Please Help renaming files
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
UNTESTED:
Code: Select all
setlocal enabledelayedexpansion
for %%a in ("oeminfo ini" "oemlogo bmp") do call :process %%~a
goto :eof
:process
if not exist %1.%2 echo %1.%2 doesn't exist && goto :eof
if not exist %1BAK.%2 ren %1.%2 %1BAK.%2 && goto :eof
set idx=1
:loop
if exist %1BAK%idx%.%2 set /a idx+=1 && goto :loop
if not %idx%==1 (
for /l %%a in (%idx%,-1,2) do (
set /a old=%%a - 1
ren %1BAK!old!.%2 %1BAK%%a.%2
)
)
ren %1BAK.%2 %1BAK1.%2
ren %1.%2 %1BAK.%2
goto :eof