Posted By

fackz on 07/18/12


Tagged

file delete dir folder remove recursively


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

tux-world
fackz


How to Remove Directories Recursively with PHP - updated method


 / Published in: PHP
 

URL: http://bsd-noobz.com/blog/how-to-remove-directories-recursively-with-php

This function removes a directory and its contents. Use with careful, no undo!

  1. function rmdir_recursive($dir){
  2. $files = scandir($dir);
  3. foreach ($files as $file) {
  4. if ($file == '.' OR $file == '..') continue;
  5. $file = "$dir/$file";
  6. if (is_dir($file)) {
  7. rmdir_recursive($file);
  8. rmdir($file);
  9. } else {
  10. unlink($file);
  11. }
  12. }
  13. rmdir($dir);
  14. }

Report this snippet  

You need to login to post a comment.