title: A recursive remove directory function for PHP?
body: <p>I am using PHP to move the contents of a images subfolder</p>
  
  <blockquote>
    <p>GalleryName/images/</p>
  </blockquote>
  
  <p>into another folder. After the move, I need to delete the GalleryName directory <em>and everything else inside it</em>. </p>
  
  <p>I know that <code>rmdir()</code> won't work unless the directory is empty. I've spent a while trying to build a recursive function to <code>scandir()</code> starting from the top and then <code>unlink()</code> if it's a file and <code>scandir()</code> if it's a directory, then <code>rmdir()</code> each empty directory as I go. </p>
  
  <p>So far it's not working exactly right, and I began to think -- <strong>isn't this a ridiculously simple function that PHP should be able to do?</strong> Removing a directory?</p>
  
  <p>So is there something I'm missing? Or is there at least a proven function that people use for this action? </p>
  
  <p>Any help would be appreciated.</p>
  
  <p><strong>PS I trust you all here more than the comments on the php.net site -- there are hundreds of functions there but I am interested to hear if any of you here recommend one over others.</strong></p>