title: If a variable does not exist in a batch
body: <p>I am stuck.  I have a section of a script that looks for a filenumber, and if it exists, I want it to go to the next command of the script.  If it does not exist, I want it to go back to the spot where the user enters the filenumber again.  Basically, if they enter a file number that does not exist, I want them to re-enter the filenumber.  If it does exist, I wnat them to proceed.  What I am getting is a loop and I can't figure out where I can get out of it.  Here is the code I have</p>
  <pre><code>    :FileNum
  cls
  set /P &quot;FileNumber=Please enter File Number: &quot;
  if defined FileNumber for /R &quot;\bpclient\A001\M0093&quot; %%I in (&quot;*%FileNumber%*.xml&quot;) do copy /Y &quot;%%I&quot; &quot;\IlnevalExtractionTool\Data\&quot;
  
  IF NOT EXIST &quot;%FileNumber%&quot; (
     echo File Number %FileNumber% Does Not Exist
     echo Try again
     pause
     goto :FileNum 
  )
  IF EXIST &quot;%FileNumber%&quot; (
  goto: result   
  ) 
  @echo off
  
  :result
  cls
  @echo off
  copy Data\*.xml Results.txt
  </code></pre>
  <p>If I enter a filenumber that exists, it copies them to the data folder, but then gives me the echo text I have for &quot;File Number XXXX Does not exist. try again&quot; and takes me back to the Please Enter File Number prompt.  How can I get it to go to the result section of the script if the variable exists, but loop back if it doesn't?</p>