title: Windows batch file: loop through parameters and test if param is file on disk?
body: <p>I am trying to write a batch file that will loop through command-line parameters, test whether each is a valid filename, and if so, set two variables. (It will also do more than this, but one question at a time seems best.)</p>
  
  <p>There is a lot of advice out there about this kind of question, but after many hours, I still can't make it work. I've tried a dozen variations on the basic idea below (which tries to set the path and filename.extension from the parameter if the file exists. </p>
  
  <pre><code>setlocal EnableDelayedExpansion
  echo on
  
  FOR %%a IN (%*) DO (
  if exist %%a set VDOSPATH="%~dp1"
  if exist %%a set VDOSFILE="%~nx1"
  echo !VDOSFILE! !VDOSFILE!
  ) 
  </code></pre>
  
  <p>Basically, everything about this is wrong. It sets the variables whether or not the file exists, and it doesn't seem to loop through the parameters, but keeps setting the same variable. I'm trying it with these parameters (where the second is a file that really does exist)</p>
  
  <pre><code>a_parameter c:\pathto\existingfile.ext another_parameter
  </code></pre>
  
  <p>I'll be very grateful for any help with this.</p>