title: Batch Script: Moving Files from One Folder to Another and Deleting Source Folder
body: <p>I wish to iterate through a directory containing a dynamic amount of subdirectories (I will be reusing this code for different directories on this machine, one directory has about 160 subdirectories, another has over 1000, etc) and within those subdirectories, there are subdirectories containing folders that contain files. I'd like to move all of the files in the source folder to the destination folder and once all of the files have been moved, I'd like for the source folder to be deleted. </p>
  
  <p>From</p>
  
  <pre><code> Source
        (dynamic amount of subdirectories)
              Site Visits
                   Field Notes (Destination Folder)
                   Levels (Source folder)
  </code></pre>
  
  <p>To</p>
  
  <pre><code> Source
        (dynamic amount of subdirectories)
              Site Visits
                   Field Notes
  </code></pre>
  
  <p>Here's the code that I have so far:</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL EnableExtensions
  set "source=\\igsascewfszeus\ILWSC_Data\dataarchive\groundwater\data sites\"
  set "target=\\igsascewfszeus\ILWSC_Data\dataarchive\groundwater\data sites\"
  for /d %%i in ("%source%\*") do (
     pushd "%source%\%%~nxi\site visits\levels prior to WY2016"
     robocopy "%source%\%%~nxi\site visits\levels prior to WY2016" "%target%\%%~nxi\site visits\field notes prior to WY2016" /e /copyall /move
     rd "%source%\%%~nxi\site visits\levels prior to WY2016"
  )
  </code></pre>
  
  <p>I'm new to batch scripting so, I would really appreciate if you can help me in some way. Thanks!</p>