PHP recursive remove directory


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.