Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Using IF in a batch file  (Read 3154 times)

0 Members and 1 Guest are viewing this topic.

dannyboy

  • Guest
Using IF in a batch file
« on: November 24, 2004, 07:53:49 AM »
I want to create a batch file that starts out by checking if a certain file exists. If the file exists then the rest of the batch file will run, if not it will exit: Like this

If file exists
do code
Else
Exit

Can anyone tell me what syntax I would need for this ?

thanks in advance

Dan

2k dummy

  • Guest
Re: Using IF in a batch file
« Reply #1 on: November 24, 2004, 09:16:27 AM »
If not exist <path><filename> goto :none
[code to executed]
goto :end
:none
echo File does not exist - no action taken
:end

If you want to get fancy, you can keep the message on screen for x number of seconds and exit automatically. For immediate termination, simply type exit following :end