title: second command in a batch for loop
body: <p>I want to write a code in batch like the following:</p>
  
  <pre><code>for %%a in (%list%) do (
      command1
      command2
      command3
      command4
      .
      .  
      .
  )
  </code></pre>
  
  <p>The first command for the first element of the list is executed correctly. But in command2 there are errors. In the cmd-window I can see what happend. And in the command isn't changed the %%a to the value. There is a "%a" instead of the value. In my code there is "%%a" exactly like in command1. </p>
  
  <p>What is the mistake here? How can I execute more than one command in a batch-for-loop?</p>
  
  <p>complete script:</p>
  
  <pre><code>set machines=pc1 pc2 pc3 pc4 
  set source1="\\%%a\c$\Data1"
  set source2="\\%%a\c$\Data2"
  set dest1="\\server\share\%%a\data1\%date%
  set dest2="\\server\share\%%a\data2\%date%
  set log1=\\server\share\log\log_%date%_data1.txt
  set log2=\\server\share\log\log_%date%_data2.txt
  set mail="success"
  set errormail="error"
  set betreff="successmail"
  set errorbetreff="errormail"
  set empf="dummy@test.com" 
  set blat="pathtoblat\blat.exe"
  set error=0
  
  for %%a in (%machines%) do (
  
      %windir%\system32\robocopy.exe %source1% %dest1% /e /COPYALL /log:%log1%
  
      if %ERRORLEVEL% EQU 16 echo ***FATAL ERROR*** &amp; goto error
      ... different errorlevels
      if %ERRORLEVEL% EQU 0 echo No Change &amp; goto next
  
  
  
      :error
      set error=1
  
  
  
      :next
      %windir%\system32\robocopy.exe %source2% %dest2% /e /COPYALL /log:%log2%
  
      if %ERRORLEVEL% EQU 16 echo ***FATAL ERROR*** &amp; goto errormail
      ... different errorlevels
      if %ERRORLEVEL% EQU 0 echo No Change
  
  
  
      if error==1 goto errormail
      goto mail
  
  
  
      :errormail
      %blat% -to %empf% -f %COMPUTERNAME%@test.com -server 172.y.y.y -s %errorbetreff% -body %errormail% -attacht %log1%,%log2%
      goto loeschen
  
      :mail
      %blat% -to %empf% -f %COMPUTERNAME%@test.com -server 172.y.y.y -s %betreff% -body %mail%
  
      :loeschen
      setlocal enableextensions disabledelayedexpansion
      pushd "\\server\share\backup\%COMPUTERNAME%\data1" &amp;&amp; (
          for /f "skip=2 delims=" %%a in (
              'dir /b /ad /tc /o-d'
          ) do rmdir /s /q "%%~fa"
          popd
      )
  
      setlocal enableextensions disabledelayedexpansion
      pushd "\\server\share\backup\%COMPUTERNAME%\data2" &amp;&amp; (
          for /f "skip=2 delims=" %%a in (
              'dir /b /ad /tc /o-d'
          ) do rmdir /s /q "%%~fa"
          popd
      )
  
      setlocal enableextensions disabledelayedexpansion
      pushd "\\server\share\log" &amp;&amp; (
          for /f "skip=4 delims=" %%a in (
              'dir /b /a-d /tc /o-d'
          ) do del /q "%%~fa"
          popd
      )
  )
  </code></pre>
  
  <p>Thanks</p>