Need script to rename file and use the "if exist and Go To" to jump to next name if the file already exists, without stopping and asking for any user intervention.
such as: ren "%systemroot%\system32\shell32.dll" "shell32.dll.OLD"
and if that exsist then Go To next such as OLD2 or OLD3 etc.
Any ideas on how to do this?
Thanks for any help..
** IF EXSIST ** Help
Moderator: DosItHelp
Re: ** IF EXSIST ** Help
You could try something like that:
Regards
aGerman
Code: Select all
@echo off &setlocal
set "Xpath=%systemroot%\system32\"
set "Xname=shell32.dll"
set "Xext=.old"
:: check if the origin file exists
if not exist "%Xpath%%Xname%" goto :EOF
:: look for extension .old
if not exist "%Xpath%%Xname%%Xext%" (
set "Newext=%Xext%"
goto REN
)
:: look for extension .old2 etc.
set /a n=1
:LOOP
set /a n+=1
if not exist "%Xpath%%Xname%%Xext%%n%" (
set "Newext=%Xext%%n%"
goto REN
)
goto LOOP
:: rename the file
:REN
ren "%Xpath%%Xname%" "%Xname%%Newext%"
Regards
aGerman