title: PHP flatten a directory
body: <p>I'm using <a href="http://flysystem.thephpleague.com/docs/" rel="nofollow noreferrer">flysystem</a> to work with my files.</p>
  
  <p>I don't see an easy way to flatten a directory so I used this</p>
  
  <pre><code>public function flattenDir($dir, $destination = null) {
    $files = find($dir . '/*');
    foreach ($files as $file) {
         $localdir = dirname($file);
  
         if (!isDirectory($file)) {
              $destination = $dir . '/' . basename($file);
              move($file, $destination);
         }
         if (isDirectory($localdir) &amp;&amp; isEmptyDirectory($localdir) &amp;&amp; ($localdir != $dir)) {
              remove($localdir);
         }
    }
  }
  </code></pre>
  
  <p>Is there an easier way by using flysystem?</p>