Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple batch file problem

Status
Not open for further replies.

Callahan

Technical User
Nov 21, 2001
174
GB
This is a very simple batch file I'm using to copy check if the company wallpaper is installed and if it isn't, install it. It works but not the way I want it to. I want it to check if the wallpaper already exists and not try to install it if it does. But for some reason it installs it regardless.

Can someone point out why?

Cheers.

:CHECK1
IF NOT EXIST C:\Windows\Web\Wallpaper\ffback.jpg GOTO :INSTALL_JPG ELSE GOTO :CHECK2

:CHECK2
IF NOT EXIST C:\Windows\Web\Wallpaper\ffback.bmp GOTO :INSTALL_BMP ELSE GOTO :END

:INSTALL_JPG
Copy "\\server\Desktop Settings\ffback.jpg" C:\Windows\Web\Wallpaper

:INSTALL_BMP
Copy "\\server\Desktop Settings\ffback.bmp" C:\Windows\Web\Wallpaper

:END
 
Correction:

:CHECK1
IF NOT EXIST C:\Windows\Web\Wallpaper\ffback.jpg GOTO :INSTALL_JPG ELSE GOTO :CHECK2

:INSTALL_JPG
Copy "\\server\Desktop Settings\ffback.jpg" C:\Windows\Web\Wallpaper

:CHECK2
IF NOT EXIST C:\Windows\Web\Wallpaper\ffback.bmp GOTO :INSTALL_BMP ELSE GOTO :END

:INSTALL_BMP
Copy "\\server\Desktop Settings\ffback.bmp" C:\Windows\Web\Wallpaper

:END
 
Try this:

:CHECK1
IF NOT EXIST C:\Windows\Web\Wallpaper\ffback.jpg (GOTO :INSTALL_JPG) ELSE (GOTO :CHECK2)

:INSTALL_JPG
Copy "\\server\Desktop Settings\ffback.jpg" C:\Windows\Web\Wallpaper

:CHECK2
IF NOT EXIST C:\Windows\Web\Wallpaper\ffback.bmp (GOTO :INSTALL_BMP) ELSE (GOTO :END)

:INSTALL_BMP
Copy "\\server\Desktop Settings\ffback.bmp" C:\Windows\Web\Wallpaper

:END
 
get rid of the ":" in your GOTO statements?

so "GOTO :INSTALL_JPG"

should be "GOTO INSTALL_JPG"

the ":" is used to mark out the labels in the file, perhaps?

Kind Regards,
Matthew Bourne
"Find a job you love and never do a day's work in your life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top