title: Using find and exec to create directories and then work with relative path to that directory
body: <p>I have a bunch of .emlx Apple Mail files in structured folders, which I would like to import into Apple Mail. I know I can do this manually, by renaming the folder to folder.mbox, and then placing the .emlx files in a nested folder called "Messages."</p>
  
  <p>I have hundreds of these folders, so I'm attempting to do it with bash instead of manually.</p>
  
  <p>I can set up the basic structure like so:</p>
  
  <pre><code>find /path/to/folders/* -type d -exec mv {} {}.mbox \; -exec mkdir {}.mbox/Messages \;
  </code></pre>
  
  <p>But I'm having trouble figuring out how to move the .emlx files into the newly created subfolder. I tried this:</p>
  
  <pre><code>find /path/to/folders/ -name \*.emlx -print0 | xargs -0 -I {} mv {} ./Messages/
  </code></pre>
  
  <p>... which I figured was a long shot, but surely there's some way of dealing with the list of files that <code>find</code> generates relative to each result's path.</p>