Return to Snippet

Revision: 58493
at July 18, 2012 12:29 by fackz


Initial Code
function rmdir_recursive($dir){
  $files = scandir($dir);
  foreach ($files as $file) {
    if ($file == '.' OR $file == '..') continue;
    $file = "$dir/$file";
    if (is_dir($file)) {
      rmdir_recursive($file);
      rmdir($file);
    } else {
      unlink($file);
    }
  }
  rmdir($dir);
}

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

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

Initial Title
How to Remove Directories Recursively with PHP -  updated method

Initial Tags
file

Initial Language
PHP