Link to home
Create AccountLog in
Avatar of IT Guy
IT Guy

asked on

if exist do not copy on bat script

see bat script below - i want to make sure that when the script runs if the file exists it just go to end and if the file does not exist then execute
does this look right


@echo off  
setlocal
set userdir=%localappdata%\Microsoft\Office
set remotedir=\\domain.com\netlogon\Deployments\CustomOfficeRibbon
if not exist "%userdir%\Excel.officeUI" copy "%remotedir%\Excel.officeUI" "%userdir%\Excel.officeUI"
rem pause
endlocal
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Bill Prew
Bill Prew

And just so you know, keep in mind that BAT scripts have a basic IF ... THEN ... ELSE syntax as well, so you can do things like:

@echo off  
setlocal

set userdir=%localappdata%\Microsoft\Office
set remotedir=\\domain.com\netlogon\Deployments\CustomOfficeRibbon

if not exist "%userdir%\Excel.officeUI" (
    copy "%remotedir%\Excel.officeUI" "%userdir%\Excel.officeUI"
) else (
    echo INFO: File "%userdir%\Excel.officeUI" already exists, not copied.
)

rem pause
endlocal

Open in new window

~bp