Delete directory and its content recursively


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



Copy this code and paste it in your HTML
  1. <?php
  2. function rrmdir($dir) {
  3. if (is_dir($dir)) {
  4. $objects = scandir($dir);
  5. foreach ($objects as $object) {
  6. if ($object != "." && $object != "..") {
  7. if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
  8. }
  9. }
  10. reset($objects);
  11. rmdir($dir);
  12. }
  13. }
  14. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.