title: Batch File to archive files based on their name
body: <p>I have text files that I need to archive daily and would like to automate it.
  There are about 100 User Folders and each User folder has 20 subfolders.</p>
  
  <pre><code>Ex User Folder structure:
      D:\Logs\John Hayse\01
      D:\Logs\John Hayse\02
      D:\Logs\John Hayse\03
      etc... up to D:\Logs\John Hayse\20
  
  Ex filenames:
      John.Hayes.T01.Daily.Log.txt
      John.Hayes.T02.Daily.Log.txt
      John.Hayes.T04.Tasks.To.Complete.txt
      Billy.Gavin.T02.Daily.Logs.txt
  </code></pre>
  
  <p>I started righting a batch file that does hundreds of if exist statements like this:</p>
  
  <pre><code>if exist D:\John.Hayes.T01* move D:\John.Hayes.T01* D:\Logs\John Hayse\01"
  if exist D:\John.Hayes.T02* move D:\John.Hayes.T02* D:\Logs\John Hayse\02"
  </code></pre>
  
  <p>If I create a separate text file containing all the Users folders:</p>
  
  <pre><code>dir "D\Logs" /b /a:d &gt;D:\UserFolderList.txt
  </code></pre>
  
  <p>How would I use that to create the if exist statement once and loop through all of the Users files and place them in the proper User folder and in their corresponding subfolder ##?</p>
  
  <pre><code>Ex.
  D:\John.Hayes.T02.Daily.Log.txt archive to D:\Logs\John Hayes\02
  </code></pre>
  
  <p>The users files always start with their FirstName.LastName.T## but the User's folder has a space instead of a '.' in between their First and Last name.</p>