title: DOS Batch file - Copy file based on filename elements
body: <p>I need to sort alot of files based on their filename. I would like to use a batch file to do it. I do know what I want but I am not sure of the correct syntax.</p>
  
  <p>Example of filenames I work with: (They are all in the same directory originally)  </p>
  
  <pre><code>2012_W34_Sales_Store001.pdf  
  2012_W34_Sales_Store002.pdf  
  2012_W34_Sales_Store003.pdf  
  
  2012_November_Sales_Store001.pdf  
  2012_November_Sales_Store002.pdf  
  2012_November_Sales_Store003.pdf
  </code></pre>
  
  <p>I would like to extract the information that are located between the "_" signs and put them into a different variable each time. The lenght of the informations contained between the _ signs will be different everytime.</p>
  
  <pre><code>Example:
  var1="2012"
  var2="W34" (or November)
  var3="Sales"
  var4="001"
  </code></pre>
  
  <p>If I am able to do this, I could then copy the files to the appropriate directory using</p>
  
  <pre><code>move %var1%_%var2%_%var3%_%var4%.pdf z:\%var3%\%var4%\%var1%\%var2%
  </code></pre>
  
  <p>It would need to loop because I have Store001 to Store050.
  Also, there are not only Sales report, many others are available.</p>
  
  <p>I hope I am clear.</p>
  
  <p>Please help me realize this batchfile!</p>