Posted By

luman on 06/29/06


Tagged

file delete dir


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

daniel
katxorro70


recursiveDelete


 / Published in: PHP
 

  1. function recursiveDelete($dir)
  2. {
  3.  
  4. if ($handle = @opendir($dir))
  5. {
  6. while (($file = readdir($handle)) !== false)
  7. {
  8. if (($file == ".") || ($file == ".."))
  9. {
  10. continue;
  11. }
  12. if (is_dir($dir . '/' . $file))
  13. {
  14. // call self for this directory
  15. recursiveDelete($dir . '/' . $file);
  16. }
  17. else
  18. {
  19. unlink($dir . '/' . $file); // remove this file
  20. }
  21. }
  22. @closedir($handle);
  23. rmdir ($dir);
  24. }
  25. }

Report this snippet  

You need to login to post a comment.