title: Batch that sets a variable equal to a line in a text file, run several commands, repeat with next line
body: <p>I have over 2 million folders split up across different locations. These folders contain old archives of photos labeled by work order number. I created a batch file a while back that automatically searches through these folders for a specific folders based on user input. Right now i have it only returning one order at a time.</p>
  
  <p>I want to modify the script to restore about 200 folders to a location on my desktop. I have a list of these folders in a text file. I tried to run my script, but it only returns the first order in the text file. I need it to loop through and move on to the next line each time. If the folder cannot be found, I would like it to just move on to the next line. Any help would be greatly appreciated. </p>
  
  <pre><code>:start
  @echo off
  
  ::::::::::::::::::::::::::
  :: Sets the order number::
  ::::::::::::::::::::::::::
  
  for /F %%G IN (E:\Desktop\test.txt) DO set Name=%%G
  
  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ::Locates the order and sets the location variable to the directory where the order is stored::
  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Feb2012\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Feb2012&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\March2012\%name%" set location=\\10.10.32.33\Backups\March2012&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\Archive\%name%" set location=\\10.10.32.33\Backups\Archive&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order4\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order4&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order3\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order3&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order2\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order2&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order1\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order1&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order5\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order5&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order6\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order6&amp;&amp; goto restore
  if exist "\\10.10.32.33\Backups\USB_Order_Backup\Order7\%name%" set location=\\10.10.32.33\Backups\USB_Order_Backup\Order7&amp;&amp; goto restore
  
  
  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  ::If the order cannot be found, the failure message will be displayed::
  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  
  :fail
  goto start
  
  :::::::::::::::::::::::::::::::
  ::Restores the missing photos::
  :::::::::::::::::::::::::::::::
  
  :restore
  xcopy %location%\%name% "E:\Desktop\Restored Photos\%name%" /s /i /e /x /h
  goto start
  </code></pre>