title: using multiple command for loops in batch files
body: <p>I'm trying to use multiple line for loops without success - code just seems to bomb out. I've switched on EnableDelayedExpansion but that doesn't seem to help either :-( The code seems to exit after "echo start for loop".</p>
  
  <p>Any ideas why this doesn't work would be much appreciated :-)</p>
  
  <p>Thanks, Helen.</p>
  
  <pre><code>:: script to rename tv/radio folders with issue date.
  
  @echo off
  :: All vars set in this file will be local:
  SETLOCAL
  setlocal EnableDelayedExpansion
  
  :SetDate
  echo.
  set /P NewDate=Please enter date to rename to (yymmdd) or "x" to exit:
  echo.
  echo new date = %NewDate%
  :: Loop to user input until a character is entered:
  if "%NewDate%"=="" GOTO Error
  If "%NewDate%"=="x" GOTO Exit
  :: User has entered a value so confirm it is correct.
  GOTO ConfirmDate
  
  :ConfirmDate
  echo.
  set /P Confirmation=Is this date correct? (y/n):
  echo.
  echo confirmation = %Confirmation%
  if "%Confirmation%"=="y" GOTO RenameFolders
  :: Else
  GOTO SetDate
  
  :RenameFolders
  :: for each folder name containing "xxx", replace "xxx" with the new date
  echo.
  echo start for loop
  for /D %%D in ("?xxx*") do (
      set "PDIR=%%~fD" &amp; set "NAME=%%~nxD"
      echo check whether folder exists
      if EXIST "!NAME:xxx=%NewDate%!" (
          echo.
          echo folders already exist! - remove them and try again!
          GOTO :End
      ) ELSE (
          move "!PDIR!" "!NAME:xxx=%NewDate%!"
      )
  )
  echo.
  echo Folder rename is complete. Thank you.
  GOTO End
  
  :Error
  echo.
  echo You did not enter a date!!
  GOTO SetDate
  
  :Exit
  echo.
  echo User requested exit, bye bye!
  GOTO End
  
  :End
  ::Remember to end command for local vars:
  ENDLOCAL
  :: exit script
  </code></pre>