title: Unflattening a directory structure based on filenames
body: <p>This is the inverse of the "flatten" operation described in this question: <a href="https://stackoverflow.com/questions/12032503/flattening-a-directory">Flattening a directory</a></p>
  
  <p>I would like a batch script that will go through each file in a "flattened" directory and put them back into their original directories, creating the directories as necessary</p>
  
  <p>So if the following files were in my folder:</p>
  
  <pre><code>images-nature-dcim001.jpg
  images-nature-dcim002.jpg
  images-dcim003.jpg
  images-indoors-dcim004.jpg
  </code></pre>
  
  <p>It would produce the resulting directory structure, creating the directories and moving (or copying) the files into the correct folder.</p>
  
  <pre><code>images
    dcim003.jpg
    nature
      dcim001.jpg
      dcim002.jpg
    indoors
      dcim004.jpg
  </code></pre>
  
  <p>Note: the example uses hyphens to separate the directories, but they can be any character.</p>