title: Flatten complex directory structure in Python
body: <p>I want to move files from a complex directory structure to just one place. For example i have this deep hierarchy:</p>
  
  <pre><code>foo/
      foo2/
          1.jpg
      2.jpg
      ...
  </code></pre>
  
  <p>I want it to be:</p>
  
  <pre><code>1.jpg
  2.jpg
  ...
  </code></pre>
  
  <p>My current solution:</p>
  
  <pre><code>def move(destination):
      for_removal = os.path.join(destination, '\\')
      is_in_parent = lambda x: x.find(for_removal) &gt; -1
      with directory(destination):
          files_to_move = filter(is_in_parent,
                                 glob_recursive(path='.'))
      for file in files_to_move:
          shutil.move(file, destination)
  </code></pre>
  
  <p>Definitions: <a href="https://stackoverflow.com/a/3012921/596361"><code>directory</code></a> and <a href="https://stackoverflow.com/a/2186565/596361"><code>glob_recursive</code></a>. Note, that my code only moves files to their common parent directory, not an arbitrary destination.</p>
  
  <p>How can i move all files from a complex hierarchy to a single place succinctly and elegantly?</p>