title: How do i delete multiple files from a MS DOS batch file using a wildcard when the path includes spaces?
body: <p>Say I have a directory with the following files in it:</p>
  
  <p>Test.bat
  Test_a.txt
  Test_b.txt
  Test_v1.zip
  Test_v2.zip
  Test_v3.zip</p>
  
  <p>I want to delete all <code>Test_v*.zip</code> quietly (no error messages logged to screen). I can achieve this with the following script:</p>
  
  <pre><code>@ECHO OFF
  SET OLD_ZIPS=^
  C:\Tmp\Test_v*.txt;^
  C:\Tmp\Test_a.txt
  
  ECHO Deleting the following files: %OLD_ZIPS%
  
  FOR %%Y IN (%OLD_ZIPS%) DO (
  IF EXIST %%Y (
  ECHO  Deleting %%Y
  DEL /Q %%Y)
  )
  
  PAUSE
  </code></pre>
  
  <p>This works fine:</p>
  
  <pre><code>Deleting the following files: C:\Tmp\Test_v*.txt;C:\Tmp\Test_a.txt
  Deleting "C:\Tmp\Test_v1.txt"
  Deleting "C:\Tmp\Test_v2.txt"
  Deleting "C:\Tmp\Test_a.txt"
  Press any key to continue . . .
  </code></pre>
  
  <p><em>Unless</em> of course the file paths contain spaces. So in the example above, if I change <code>C:\Tmp\Test_v*.txt</code> to <code>C:\Tmp with spaces\Test_v*.txt</code> I get:</p>
  
  <pre><code>Deleting the following files: C:\Tmp test\Test_v*.txt;C:\Tmp test\Test_a.txt
  Press any key to continue . . .
  </code></pre>
  
  <p>How can I stop it baulking at the spaces?</p>
  
  <p><strong>Edit</strong> - I've tried spaces as per Alex K's answer (plus a little more debug) and it looks like perhaps the for loop isn't splitting things up as I expect:</p>
  
  <pre><code>@ECHO OFF
  SET OLD_ZIPS=^
  C:\Tmp test\Test_v*.txt;^
  C:\Tmp test\Test_a.txt
  
  ECHO Deleting the following files: %OLD_ZIPS%
  
  FOR %%Y IN (%OLD_ZIPS%) DO (
  ECHO  Checking existance of "%%Y"
  IF EXIST "%%Y" (
  ECHO  Deleting "%%Y"
  DEL /Q "%%Y")
  )
  
  PAUSE
  </code></pre>
  
  <p>..gives me:</p>
  
  <pre><code>Deleting the following files: C:\Tmp test\Test_v*.txt;C:\Tmp test\Test_a.txt
   Checking existance of "C:\Tmp"
   Checking existance of "C:\Tmp"
   Checking existance of "test\Test_a.txt"
  </code></pre>