title: Windows Batch file to move X number of files from folder to folder
body: <p>I'm trying to use a batch file to move files in blocks of 30 if there are less than 20 files in <code>%DataLoc%</code>.  I modified code from <a href="https://stackoverflow.com/questions/5552368/windows-batch-file-script-to-pick-random-files-from-a-folder-and-move-them-to-an/9123811#9123811">a prior question</a>.  The problem is in the <code>FMove</code> section of the file.  No matter what I put in the <code>for</code> line, it gives me an error.</p>
  
  <p>I want this to have the <code>%HoldLoc%</code> value, but have been hard coding it because of errors I get.</p>
  
  <p>The environment is Windows 2008 R2 server.</p>
  
  <p>Variations I have tried, as well as with and without quotes in the parentheses:</p>
  
  <pre><code>FOR %F IN (%HoldLoc%)
  FOR %F IN (%%HoldLock%) 
  FOR %F IN (c:\Play\hold\*.tmp) 
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>SETLOCAL ENABLEEXTENSIONS
  SETLOCAL ENABLEDELAYEDEXPANSION
  
  echo on
  set DataMax=20
  set DataLoc=C:\Play\Data
  Set HoldLoc=C:\Play\Hold
  set count=0
  FOR /F %%a in ('DIR /B %DataLoc%\*.tmp') do set /A count=count+1
  if %count% GEQ %DataMax% (Goto Exit) else (GOTO FMove)
  :FMove
  Echo Gather Top 30 files
  set SrcCount=0
  set SrcMax=30
  echo %HoldLoc%
  FOR %F IN (c:\Play\hold\*.tmp) DO IF !SrcCount! LSS %SrcMax% (
      SET /A SrcCount += 1
      move /y %F  "%DataLoc%"
      )
  </code></pre>
  
  <p>Problem is that I get this in the output window, why won't the <code>C</code> be seen?</p>
  
  <pre><code>C:&gt;set /A count=count+1
  
  C:&gt;if 19 GEQ 20 (Goto Exit )  else (GOTO FMove )
  
  C:&gt;Echo Gather Top 30 files
  Gather Top 30 files
  
  C:&gt;set SrcCount=0
  
  C:&gt;set SrcMax=30
  
  C:&gt;echo C:\Play\Hold
  C:\Play\Hold
  \Play\hold\*.tmp) was unexpected at this time.
  
  C:&gt;FOR \Play\hold\*.tmp) DO IF !SrcCount! LSS 30 (
  
  C:&gt;
  </code></pre>