Posted By

ginoplusio on 02/02/10


Tagged

php dir recursive remove directory rmdir


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

derek
ginoplusio
pster
BrianCoyDesign


PHP recursive remove directory


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/02/02/recursive-remove-directory-rmdir-in-php/

  1. function rmdir_recurse($path) {
  2. $path = rtrim($path, '/').'/';
  3. $handle = opendir($path);
  4. while(false !== ($file = readdir($handle))) {
  5. if($file != '.' and $file != '..' ) {
  6. $fullpath = $path.$file;
  7. if(is_dir($fullpath)) rmdir_recurse($fullpath); else unlink($fullpath);
  8. }
  9. }
  10. closedir($handle);
  11. rmdir($path);
  12. }

Report this snippet  

You need to login to post a comment.